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

Bug#442568: glibc: floor() is giving incorrect results on alpha architecture



Package: glibc
Severity: normal

Consider the following code

$cat double_comparison.c
#include <assert.h>
#include <float.h>
#include <math.h>
#include <stdio.h>

int main() {
  double x;

  printf("%s%d\n", "DBL_MANT_DIG = ", DBL_MANT_DIG);
  x = ldexp (1.0, DBL_MANT_DIG) - 1.0;
  printf("%lf %lf\n", x, floor(x));
  assert(x == floor(x));    /* does not seem to work in alpha */
  return 0;
}

On i386 machine
$gcc -Wall double_comparison.c -lm

$./a.out
DBL_MANT_DIG = 53
9007199254740991.000000 9007199254740991.000000

However the assertion fails on alpha architecture because the value is
9007199254740991.000000 and the floor gives 9007199254740990.000000

This behaviour makes guile-1.8 (version 1.8.2+1-2) FTBFS on alpha architecture.
The corresponding build log can be found at
http://buildd.debian.org/fetch.cgi?&pkg=guile-1.8&ver=1.8.2%2B1-2&arch=alpha&stamp=1188100514&file=log

>From guile-1.8-1.8.2+1/test-suite/standalone/test-round.c the lines where the
guile-1.8 build fails is 

      /* 2^DBL_MANT_DIG-1
         In the past scm_c_round had incorrectly incremented this value, due
         to the way that x+0.5 would round upwards (in the usual default
         nearest-even mode on most systems).  */
      x = ldexp (1.0, DBL_MANT_DIG) - 1.0;
      assert (x == floor (x));      /* should be an integer already */
      assert (scm_c_round (x) == x);  /* scm_c_round should return it unchanged */

Initially I asked about this problem on debian-devel. Steve Langasek mentioned
that this is a bug in glibc. So I am filing it here. The discussion can be
found at http://lists.debian.org/debian-devel/2007/09/msg00536.html

PS: the double_comparison.c test case is written by me and has not been tested
on alpha. Please change it accordingly if there are any problems with it.


thanks
raju

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.22-2-686 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash




Reply to: