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

Bug#216800: libc6: Broken rint function for the powerpc



Package: libc6
Version: 2.3.2-7
Severity: important
Tags: patch

The rint function for the powerpc gives wrong values for negative
arguments in the rounding toward -inf and +inf modes, and probably
an incorrect sign in the rounding to -inf mode for values between
0 and 1 (-0.0 instead of +0.0). The (generic) nearbyint function
is correct however.

How about using the following code?

  if (fabs (x) < TWO52)
    {
      if (x > 0.0)
        {
          x += TWO52;
          x -= TWO52;
          if (x == 0.0)
            x = 0.0;
        }
      else if (x < 0.0)
        {
          x -= TWO52;
          x += TWO52;
          if (x == 0.0)
            x = -0.0;
        }
    }

The tests with 0.0 corrects the sign of the result (I don't know
if this is standardized, but this is more consistent like that).

I have a testing program and the above implementation here:

    http://www.vinc17.org/software/nearestint.c

For instance, try: ./nearestint 4.5 1

-- System Information:
Debian Release: testing/unstable
Architecture: powerpc
Kernel: Linux ay 2.4.22-powerpc #1 Sat Sep 27 04:08:08 CEST 2003 ppc
Locale: LANG=C, LC_CTYPE=en_US.ISO8859-1

Versions of packages libc6 depends on:
ii  libdb1-compat                 2.1.3-7    The Berkeley database routines [gl

-- no debconf information



Reply to: