From mboxrd@z Thu Jan 1 00:00:00 1970 From: richard@wetafx.co.nz To: gcc-gnats@gcc.gnu.org Subject: other/3657: Documentation bug re "Problems with floating point computation" Date: Wed, 11 Jul 2001 23:26:00 -0000 Message-id: <20010712061601.16909.qmail@sourceware.cygnus.com> X-SW-Source: 2001-07/msg00320.html List-Id: >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: