This is the mail archive of the gcc-patches@gcc.gnu.org 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]

Re: Handling non-constant bounds in extract_range_from_cond



On Nov 25, 2004, at 09:36, Richard Kenner wrote:


It fixes an ICE and I thought it was just cc1221d (I meant to include
that in my email; sorry if I forgot).  I show c34002a as working in a
recent run I did, but c460007 is still failing.


c460007 is on my plate. Interesting case of wrong rounding in float-to-int conversion, fix is known, patch will follow.

Basically, for rounding to nearest int (rounding halfway values
away from zero), one shouldn't do add/subtract 0.5 and then
truncate, but add/subtract the T'Pred of 0.5, where T is a
floating-point type and 'Pred is the predecessor function.

This is because the sum of 0.5 and T'Pred (0.5) is exactly
between two representable numbers and therefore rounded to 1.
Additionally, for floating-point integers with the radix
point directly following the mantissa, adding 0.5 also ends
up halfway two numbers which results in rounding these integers
up to the next integer.

Computing T'Truncate (X + Copy_Sign (T'Pred (0.5), X)) nicely
deals with all these cases.

-Geert

PS. Fortran has a similar bug.


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