other/3657: Documentation bug re "Problems with floating point computation"
richard@wetafx.co.nz
richard@wetafx.co.nz
Wed Jul 11 23:26:00 GMT 2001
>Number: 3657
>Category: other
>Synopsis: Documentation bug re "Problems with floating point computation"
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: doc-bug
>Submitter-Id: net
>Arrival-Date: Wed Jul 11 23:26:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Richard Addison-Wood
>Release: n/a
>Organization:
>Environment:
n/a
>Description:
This web page:
http://www.gnu.org/software/gcc/bugs.html
shows this example code fragment:
double min = 0.0;
double max = 0.5;
double width = 0.01;
std::cout << (int)(((max - min) / width) - 1) << std::endl;
and asserts that it "might print 50 on some systems
and optimization levels, and 51 on others."
I assert that it is only reasonable that this code
would be expected to print 49 or 48.
I know this is a bit picky, since the main point
of the example is to show that finite representation
of real numbers has limitations and to be aware
of rounding issues. However, it is easy to correct
the comment.
>How-To-Repeat:
Compile and run the example on a few systems
and at different optimization levels. The
results should be 49 or 48.
>Fix:
Revise the example code or the comment about what
the result should be.
It may also be useful to show, for this trivial
example, how to revise it to be more reliable.
For example:
(int)(((max - min) / width) - 0.5
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list