bug-gsl
[Top][All Lists]
Advanced

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

[Bug-gsl] [bug #47348] Use of incorrect ideom floor(x+0.5)


From: M Welinder
Subject: [Bug-gsl] [bug #47348] Use of incorrect ideom floor(x+0.5)
Date: Sat, 05 Mar 2016 22:58:11 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0

URL:
  <http://savannah.gnu.org/bugs/?47348>

                 Summary: Use of incorrect ideom floor(x+0.5)
                 Project: GNU Scientific Library
            Submitted by: terra
            Submitted on: Sat 05 Mar 2016 10:58:10 PM GMT
                Category: None
                Severity: 3 - Normal
        Operating System: Linux
                  Status: None
             Assigned to: None
             Open/Closed: Open
                 Release: 2.1
         Discussion Lock: Any

    _______________________________________________________

Details:

A quick grep through the source code shows that the ideom
floor(x+0.5) is used quite a few places in the code with the
intention of rounding to nearest integer.

That ideom does not work for all x.

Specifically, there are two classes of numbers for which it
does not work:

1. The largest positive number strictly less than 0.5.  This
   will round to 1, but it should round to 0.  This happens
   because the addition rounds to 1 which floor then doesn't
   touch.

2. A long sequence of even integers starting at 2^52.
   For these numbers (and their negative cousins) adding 0.5
   will actually add 1.

So, for example:
./specfunc/fermi_dirac.c:  const int j_integer = ( fabs(j - floor(j+0.5)) <
100.0*GSL_DBL_EPSILON );
./specfunc/hyperg_1F1.c:  const int bma_integer = ( bma - floor(bma+0.5) <
_1F1_INT_THRESHOLD );

2^52 isn't recognized as an integer here.  I have no idea
what consequences that has.


./specfunc/ellint.c:  double nc = floor(phi/M_PI + 0.5);
./specfunc/ellint.c:  double nc = floor(phi/M_PI + 0.5);
./specfunc/ellint.c:  double nc = floor(phi/M_PI + 0.5);
./specfunc/ellint.c:  double nc = floor(phi/M_PI + 0.5);
./specfunc/hyperg_2F1.c:  const int intd  = floor(d+0.5);
./specfunc/hyperg_2F1.c:  const double rinta = floor(a + 0.5);
./specfunc/hyperg_2F1.c:  const double rintb = floor(b + 0.5);
./specfunc/hyperg_2F1.c:  const double rintc = floor(c + 0.5);
./specfunc/hyperg_2F1.c:  const double rintc = floor(c + 0.5);
./specfunc/hyperg_2F1.c:  const double rinta = floor(a + 0.5);
./specfunc/hyperg_2F1.c:  const double rintb = floor(b + 0.5);
./specfunc/hyperg_2F1.c:  const double rintc = floor(c + 0.5);
./specfunc/hyperg_2F1.c:  const double rintc = floor(c  + 0.5);
./specfunc/hyperg_2F1.c:  const double rinta = floor(aR + 0.5);

Let's hope getting the right rounded values isn't important.





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?47348>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]