Bug 1514953 - gawk ROUNDMODE "A" (roundTiesToAway) gives incorrect results
Summary: gawk ROUNDMODE "A" (roundTiesToAway) gives incorrect results
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gawk
Version: 26
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: David Kaspar // Dee'Kej
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-11-19 16:56 UTC by Don Swaner
Modified: 2017-11-22 13:02 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-11-22 08:35:58 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Don Swaner 2017-11-19 16:56:59 UTC
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.

Comment 1 Don Swaner 2017-11-20 13:01:04 UTC
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."

Comment 2 David Kaspar // Dee'Kej 2017-11-20 14:41:50 UTC
[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...

Comment 3 David Kaspar // Dee'Kej 2017-11-20 14:44:42 UTC
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. :)

Comment 4 David Kaspar // Dee'Kej 2017-11-22 08:35:58 UTC
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 --

Comment 5 Don Swaner 2017-11-22 13:02:56 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.