Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1684793 - gawk info example comparing floating point numbers is wrong
Summary: gawk info example comparing floating point numbers is wrong
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: gawk
Version: 29
Hardware: x86_64
OS: Linux
Target Milestone: ---
Assignee: David Kaspar [Dee'Kej]
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2019-03-02 14:30 UTC by Don Swaner
Modified: 2019-12-17 15:59 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed:

Attachments (Terms of Use)

Description Don Swaner 2019-03-02 14:30:41 UTC
Description of problem:

The gawk Info node "Be Careful Comparing Values" example is wrong.

It says:
     delta = 0.00001                 # for example
     difference = abs(a) - abs(b)    # subtract the two values
     if (difference < delta)
         # all ok
         # not ok

If a = 1.001 and b = 1.002, then
difference = abs(1.001) - abs(1.002) = -.001
Now -.001 is less than delta, so the test says "all OK".
However, the actual abs difference between the two values is 0.001.

The correct method:
     difference = abs(a - b)    # subtract the two values

This yields difference = abs(1.001 - 1.002) = abs(-.001) = 0.001 (correct)
and the test says "not OK".

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. NA

Actual results:

Expected results:

Additional info:

Comment 1 Andrew Schorr 2019-03-02 14:44:07 UTC
Hi, yes, this was fixed in upstream commit 417bd669 in August, 2018. So it will be in 
the next major release of gawk (coming soon)...

Comment 3 Don Swaner 2019-03-02 17:22:56 UTC
Thanks.  In oorexx, you can set FUZZ=..., which is the "delta" for floating point compares, and the user doesn't have to explicitly code the check ... and they don't get bitten by cases in which "zero" isn't less than or equal to "zero"!

Comment 4 Andrew Schorr 2019-03-02 19:17:45 UTC
Rexx is great, but awk is a different language. It should be simple enough to create an equals(x,y) function that applies a fuzz check for you.

Comment 5 Fedora Admin XMLRPC Client 2019-12-17 15:59:38 UTC
This package has changed maintainer in the Fedora.
Reassigning to the new maintainer of this component.

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