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.
--
Summary: Incorrect rounding from floating point to integer
Product: gcc
Version: 3.4.3
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P2
Component: ada
AssignedTo: bosch at gcc dot gnu dot org
ReportedBy: bosch at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18099