Bug 31179 - strange behaviour of floor rounding
Summary: strange behaviour of floor rounding
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-15 01:45 UTC by Thomas Hobiger
Modified: 2021-09-12 02:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Hobiger 2007-03-15 01:45:01 UTC
This following small program will show the problem

# report.cpp 
#include <cmath>
#include <iostream>

int main(int argc, char* argv[])

{
 double A=140.70;
 double x=floor((A*100));
 std::cout << "Testing: A = " <<  A << " --> A*100 = " << A*100 << " but floor(A*100) = " << x << "\n";
 double B=140.60;
 double y=floor((B*100));

 std::cout << "Testing: B = " <<  B << " --> B*100 = " << B*100 << " but floor(B*100) = " << y << "\n";

}

The program was compiled simply by "g++ report.cpp -o report."

For all machines available here I obtained 

Testing: A = 140.7 --> A*100 = 14070 but floor(A*100) = 14069
Testing: B = 140.6 --> B*100 = 14060 but floor(B*100) = 14060

The latter result is as expected but for A=128.7,129.7,130.7....163.7 floor rounding gives wrong results. This bug has been verified on several architectures (PIII,P3, WinXP - Cygwin) and under several versions of gcc/g++ (4.1.1 - on FC6, 4.0.2 - on RH,  3.4.6 -on RH)
Any ideas where this comes frome ???
Comment 1 Andrew Pinski 2007-03-15 05:37:22 UTC
I don't think this is a bug, 1407 and 14.7 are not exactly representable in floating point.
Comment 2 Andrew Pinski 2021-09-12 02:51:36 UTC
Actually 14070 is exactly represented but 140.7 is not.