get_d_2exp test failures: clang -emit-llvm/-flto/-O4; icc -ipo/-fast
nisse at lysator.liu.se
Tue Aug 20 21:35:47 CEST 2013
nisse at lysator.liu.se (Niels Möller) writes:
> Second problem is the ! FORMAT_RECOGNIZED case in mpn/get_d.c, maybe it
> could be fixed to be more robust.
At least I can reproduce this problem. I add the line
#define _GMP_IEEE_FLOATS 0
at the top of mpn/generic/get_d.c. Then a plain configure and make using
gcc on on gnu/linux x86_64 results in the same error,
mpz_get_d_2exp wrong on 2**54-1
result out of range, expect 0.5 <= got < 1.0
rnd_mode = 0
data[i] = 54
got =[00 00 00 00 00 00 F0 3F] 1
got exp 54
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. Or have a
check for upward rounding. But maybe one can come up with some better trick?
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
More information about the gmp-bugs