This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fix ACATS C460007

Tested on x86-linux, committed on mainline.

Re-applying earlier patch, which was correct, but uncovered
another unrelated bug in ACATS C460007. Before applying this
patch the ACATS test would check for correct rounding of
Float'Pred (Float'Pred (0.5)), which would pass. However,
the test meant to check correct rounding of Float'Pred (0.5),
which we incorrectly rounded to 1.0.

This change fixes a bug in the compile-time evaluation of the
Long_Float'Succ (0.0). Implementing Succ and Pred in terms of
other standard attributes is preferable over using routines
that try to do too much and whose specifications aren't as
solid as those of the Ada attributes.

The previous implementation would implement a rounding conversion
of a positive X of floating-point type T to integer by adding 0.5
and then truncating. This is incorrect for the predecessor of a half,
T'Pred (0.5), as T'Pred (0.5) + 0.5 lays exactly between T'Pred (1.0)
and 1.0, and therefore will be rounded to the number with even least
significant bit, which is 1.0.

Also odd floating point integers with the radix point directly
following the least significant bit of the mantissa, adding 0.5
results in a value exactly between two floating-point integers,
so these get rounded up to the next even integer instead of remaining

The new implementation addresses both issues by adding T'Pred (0.5)
instead. As shown above, this results in correct rounding for 0.5.
For all larger numbers that lay exactly halfway two integers, adding
T'Pred (0.5) will cause the mathematical result of the addition
to the next higher integer.

Although the new implementation may be a bit slower (at
compile time), this could easily be fixed by special casing
various operations in urealp.adb. This small drawback is
easily outweighed by the new approach taking 50 lines less
code and producing correct answers on targets without
gradual underflow.

2005-01-03  Geert Bosch  <>

	* eval_fat.adb: (Eps_Model,Eps_Denorm): Remove, no longer used.
	(Succ): Re-implement using Scaling, Exponent and Ceiling attributes.
	(Pred): Implement in terms of Succ.
	* trans.c (convert_with_check): Reimplement conversion of float to

Attachment: difs.7
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]