[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#216800: powerpc rint() bug



Some additional information... Here's a part of the output of my program
(on a PowerPC machine):

ay:~/wd/src/fp> ./nearestint 4.5 1
[...]
Rounding toward -oo
             -4.5  -3.5  -2.5  -1.5  -0.5   0.5   1.5   2.5   3.5   4.5
casttoint    -4    -3    -2    -1     0     0     1     2     3     4  
trunc        -4.0  -3.0  -2.0  -1.0  -0.0   0.0   1.0   2.0   3.0   4.0
floor        -5.0  -4.0  -3.0  -2.0  -1.0   0.0   1.0   2.0   3.0   4.0
ceil         -4.0  -3.0  -2.0  -1.0  -0.0   1.0   2.0   3.0   4.0   5.0
round        -5.0  -4.0  -3.0  -2.0  -1.0   1.0   2.0   3.0   4.0   5.0
nearbyint    -5.0  -4.0  -3.0  -2.0  -1.0   0.0   1.0   2.0   3.0   4.0
myrint       -5.0  -4.0  -3.0  -2.0  -1.0   0.0   1.0   2.0   3.0   4.0
rint         -4.0  -3.0  -2.0  -1.0   0.0  -0.0   1.0   2.0   3.0   4.0
[...]

"myrint" corresponds to my code. As expected, it agrees with the
nearbyint glibc function (which is correct). In short, the current
rint code for negative numbers doesn't work in the rounding modes
toward -oo and toward +oo, because it does the first subtraction in
the wrong way, so that the result is rounded in the wrong direction.

Note: do not try the code on Linux/x86, or any other processor that
runs in extended precision; it will not work (in part due to a gcc
bug). Well, if you really want to try on such a machine, you can
still use the -ffloat-store compiler switch, but the results are
not guaranteed for any input.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA



Reply to: