Description of problem: As per "info gawk", for ROUNDMODE = "A": "The rounding mode 'roundTiesToAway' rounds the result to the nearest number and selects the number with the larger magnitude if a tie occurs." However, it does not work that way. Version-Release number of selected component (if applicable): gawk-4.1.4-5.fc26.x86_64 How reproducible: 100% Steps to Reproduce: 1. Run gawk program: #!/usr/bin/gawk -Mf BEGIN { ROUNDMODE = "A" x = 2.21 printf "%4.2f\n",x printf "%3.1f\n",x exit } Actual results: 2.21 2.3 Expected results: 2.21 2.2 Additional info: Note -M option (arbitrary precision arithmetic) is supplied on hash-bang line.
As per comment by RupertPupkin at Fedora Forum (https://forums.fedoraforum.org/showthread.php?316207-Setting-gawk-ROUNDMODE&p=1798405#post1798405): "Hmm, looks like Gawk is just (unintentionally) doing with ROUNDMODE="A" what MPFR is doing with its MPFR_RNDA: it's rounding away from zero at all times, not just for ties."
[root@qeos-12 ~]# cat /etc/*-release Fedora release 26 (Twenty Six) NAME=Fedora VERSION="26 (Twenty Six)" ID=fedora VERSION_ID=26 PRETTY_NAME="Fedora 26 (Twenty Six)" ANSI_COLOR="0;34" CPE_NAME="cpe:/o:fedoraproject:fedora:26" HOME_URL="https://fedoraproject.org/" BUG_REPORT_URL="https://bugzilla.redhat.com/" PRIVACY_POLICY_URL=https://fedoraproject.org/wiki/Legal:PrivacyPolicy Fedora release 26 (Twenty Six) [root@qeos-12 ~]# rpm -q gawk mpfr gawk-4.1.4-5.fc26.x86_64 mpfr-3.1.5-3.fc26.x86_64 [root@qeos-12 ~]# cat gawk.test #!/usr/bin/gawk -Mf BEGIN { ROUNDMODE = "A" x = 2.21 printf "%4.2f\n",x printf "%3.1f\n",x exit } [root@qeos-12 ~]# gawk -f ./gawk.test 2.21 2.2 ------- Sorry, I'm unable to reproduce this. You will have to provide me with some other reproducer I guess...
Ah, I just saw your note their... *sigh* OK, I'm able to reproduce this with -M option: [root@qeos-12 ~]# gawk -M -f ./gawk.test 2.21 2.3 I will pass this to gawk upstream, so they can decide if this is a bug or not. :)
Hello Don, after discussion with upstream we have come to a conclusion this is not a bug, because you have explicitly requested non-standard rounding mode. Upstream will update the documentation (man pages) to better reflect on this, but they will not fix anything in the code - the MPFR is behaving as it should. :) Best regards, -- Dee'Kej --
I see now that "info gawk" does already say "This is only available if your version of the MPFR library supports it; otherwise, setting 'ROUNDMODE' to '"A"' has no effect." So that is already pretty clear - sorry I missed that before. But I guess clarification is needed between MPFR "round mode A" and IEEE "round mode A", which seem to be two different things. It seems odd that gawk does not provide a built-in for doing traditional rounding - though writing a user function is easy enough.