get_d_2exp test failures: clang -emit-llvm/-flto/-O4; icc -ipo/-fast

Vincent Lefevre vincent at vinc17.net
Wed Aug 21 00:06:02 CEST 2013


On 2013-08-20 21:35:47 +0200, Niels Möller wrote:
> I haven't tried to debug it, but I guess the floating point is using
> round-to-nearest or something like that. I haven't debugged it, but it
> looks like the critical oepration is the addition
> 
> 	  d += up[i] * weight;          
> 
> The safest way would be to detect, at run time if necessary, how many
> mantissa bits there are, and avoid any floating point operations which
> imply rounding, by masking of low bits of u[i] when necessary.

Using DBL_MANT_DIG is probably safe in practice, except in the case
where the processor is configured to round to single precision; it
depends on how you want to handle this. You can also do a runtime
check in the function itself (without caching the result).

> Or have a check for upward rounding.

If |x| >= |y|, then { s = x + y; e = s - x - y; } will give you the
error on the sum, so that if it is positive, this would mean that
the sum has been rounded upward. However, if you have intermediate
extended precision and s is kept in extended precision (which isn't
conforming to the ISO C standard but can happen in practice), this
won't work. This may not work either if the processor is configured
to round to single precision and x and/or y don't fit in a single
precision number.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the gmp-bugs mailing list