Rounding glitch from bigint to float
Jean-Luc-Picard-2021 opened this issue · 1 comments
Jean-Luc-Picard-2021 commented
SWI-Prolog has released a new release 8.5.20 with better
float rounding. Comparing we found:
/* SWI-Prolog 8.5.20 Ok */
?- X is float(166153499473114502559719956244594689).
X = 1.6615349947311452e+35.
/* Ciao Prolog Nok */
?- X is float(166153499473114502559719956244594689).
X = 1.661534994731145e35 ?
Our guess is that this conversion routine doesn't work
for HALF_EVEN mode:
flt64_t bn_to_float(bignum_t *bn) {
while (i > 1) {
f = f*norm2 + u;
https://github.com/ciao-lang/ciao/blob/master/core/engine/eng_bignum.c#L1043
jfmc commented
Python
>>> float(166153499473114502559719956244594689)
1.6615349947311452e+35
>>>
Javascript
> 166153499473114502559719956244594689
1.6615349947311452e+35