Bug 18099 - Incorrect rounding from floating point to integer
Summary: Incorrect rounding from floating point to integer
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 4.0.0
Assignee: Geert Bosch
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2004-10-21 17:01 UTC by Geert Bosch
Modified: 2005-02-24 18:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-10-21 17:06:06


Attachments
Test case showing failure (598 bytes, text/plain)
2004-10-21 17:04 UTC, Geert Bosch
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Geert Bosch 2004-10-21 17:01:13 UTC
Ada requires conversion of floating-point to integer to round, with halfway cases rounded away from 
zero. This is implemented by adding 0.5 to the floating-point value and then truncating, as in regular C 
float to int conversion. However, this gives wrong semantics for the predecessor of 0.5, and odd 
floating-point integers in the range 2.0**(mantissa - 1)+1.0 .. 2.0**(mantissa)-1.0 and the negative 
versions of these.

The reason is that adding 0.5 in the above cases, yields a value exactly between two 
representable floating-point numbers. So the predecessor of 0.5 is then rounded to one, and the 
floating-point integers mentioned before get rounded to the next higher integer.

I'll file a self-contained test case testing these cases.
Comment 1 Geert Bosch 2004-10-21 17:04:35 UTC
Created attachment 7396 [details]
Test case showing failure
Comment 2 Geert Bosch 2005-02-24 18:12:39 UTC
The fix for this is now in GCC 4.0.0.