This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: exp() bug?


In reply to:
: From: cygwin-owner On Behalf Of Lester Ingber
: > Sent: 05 October 2004 16:36
: 
: > I believe there is a bug in some gcc's, at least in the exp() function,
: > and at least in the way round-offs are (in)consistently treated.
: 
:   Go on?
: 
: > I first noticed some differences in results in calculations using the
: > MINGW gcc vs the Cygwin gcc on my ThinkPad XPPro machine.  I applied
: > the same code on FreeBsd and on SPARC/Solaris9.
: 
:   First go and google for "What every computer scientist should know about
: floating point", and read the entire paper.  Then try running your tests again,
: but compile them with the "-ffloat-store" option.  Then read "info gcc" about
: -ffloat-store and its effects.
: 
:   Then if you still think there's a bug, come back and describe it.  But if you've
: taken all that in, you no longer will.
: 
:     cheers, 
:       DaveK

I disagree about what the default behavior should be.  In any case, here are
runs with -ffloat-store.  I see no difference.

Lester

      +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
I believe there is a bug in some gcc's, at least in the exp() function,
and at least in the way round-offs are (in)consistently treated.

I first noticed some differences in results in calculations using the
MINGW gcc vs the Cygwin gcc on my ThinkPad XPPro machine.  I applied
the same code on FreeBsd and on SPARC/Solaris9.

If true, this is a **very** serious bug, leading to very different
answers on pretty standard (complex) calculations, as I discovered.

Here is the code for gcctest.c:
    ------------8<------------ top cut -> bottom ------------->8------------
/*
 * rm gcctest.exe; gcc -O -mno-cygwin -o gcctest.exe gcctest.c -lm; gcctest.exe
 * rm gcctest.exe; gcc -O -o gcctest.exe gcctest.c -lm; gcctest.exe
 *
 * rm gcctest.exe; gcc -O -ffloat-store -mno-cygwin -o gcctest.exe gcctest.c -lm; gcctest.exe
 * rm gcctest.exe; gcc -O -ffloat-store -o gcctest.exe gcctest.c -lm; gcctest.exe
 */

#include <errno.h>
#include <math.h>
#include <stdio.h>

int main ();

int
main ()
{
  double d;

  d = exp (log (1234567.2)) - exp (log (1234567.1));
  printf ("1234567.2-1234567.1: d = %g\n", d);
  d = exp (log (12345678.2)) - exp (log (12345678.1));
  printf ("12345678.2-12345678.1: d = %g\n", d);
  d = exp (log (123456789.2)) - exp (log (123456789.1));
  printf ("123456789.2-123456789.1: d = %g\n", d);
  d = exp (log (1234567891.2)) - exp (log (1234567891.1));
  printf ("1234567891.2-1234567891.1: d = %g\n", d);
  d = exp (log (12345678912.2)) - exp (log (12345678912.1));
  printf ("12345678912.2-12345678912.1: d = %g\n", d);
  d = exp (log (123456789123.2)) - exp (log (123456789123.1));
  printf ("123456789123.2-123456789123.1: d = %g\n", d);
  d = exp (log (1234567891234.2)) - exp (log (1234567891234.1));
  printf ("1234567891234.2-1234567891234.1: d = %g\n", d);
  d = exp (log (12345678912345.2)) - exp (log (12345678912345.1));
  printf ("12345678912345.2-12345678912345.1: d = %g\n", d);
  d = exp (log (123456789123456.2)) - exp (log (123456789123456.1));
  printf ("123456789123456.2-123456789123456.1: d = %g\n", d);
  d = exp (log (1234567891234567.2)) - exp (log (1234567891234567.1));
  printf ("1234567891234567.2-1234567891234567.1: d = %g\n", d);
  d = exp (log (12345678912345678.2)) - exp (log (12345678912345678.1));
  printf ("12345678912345678.2-12345678912345678.1: d = %g\n", d);
  d = exp (log (123456789123456789.2)) - exp (log (123456789123456789.1));
  printf ("123456789123456789.2-123456789123456789.1: d = %g\n", d);

  return 0;
}
    ------------8<------------ bottom cut <- top ------------->8------------

Here are the results:

ThinkPad/XPPRO/gcc-3.3.3
% rm gcctest.exe ; gcc -O -ffloat-store -mno-cygwin -o gcctest.exe gcctest.c -lm; gcctest.exe
OR
% rm gcctest.exe ; gcc -O -ffloat-store -mno-cygwin -o gcctest.exe gcctest.c -lm; gcctest.exe
1234567.2-1234567.1: d = 0.1
12345678.2-12345678.1: d = 0.1
123456789.2-123456789.1: d = 0.0999997
1234567891.2-1234567891.1: d = 0.0999979
12345678912.2-12345678912.1: d = 0.100002
123456789123.2-123456789123.1: d = 0.100002
1234567891234.2-1234567891234.1: d = 0.100916
12345678912345.2-12345678912345.1: d = 0.0868587
123456789123456.2-123456789123456.1: d = 0.000205994
1234567891234567.2-1234567891234567.1: d = -0.0303955
12345678912345678.2-12345678912345678.1: d = -0.0839844
123456789123456789.2-123456789123456789.1: d = -7.95313

ThinkPad/XPPRO/gcc-3.3.3
% rm gcctest.exe ; gcc -ffloat-store -O -o gcctest.exe gcctest.c -lm; gcctest.exe
OR
% rm gcctest.exe ; gcc -ffloat-store -O -o gcctest.exe gcctest.c -lm; gcctest.exe
1234567.2-1234567.1: d = 0.1
12345678.2-12345678.1: d = 0.1
123456789.2-123456789.1: d = 0.0999997
1234567891.2-1234567891.1: d = 0.099998
12345678912.2-12345678912.1: d = 0.100002
123456789123.2-123456789123.1: d = 0.100006
1234567891234.2-1234567891234.1: d = 0.10083
12345678912345.2-12345678912345.1: d = 0.0859375
123456789123456.2-123456789123456.1: d = 0
1234567891234567.2-1234567891234567.1: d = 0
12345678912345678.2-12345678912345678.1: d = 0
123456789123456789.2-123456789123456789.1: d = 0

FreeBSD-4.10/gcc-2.95.4
% rm gcctest.exe ; gcc -O -ffloat-store -o gcctest.exe gcctest.c -lm ; gcctest.exe
OR
% rm gcctest.exe ; gcc -O -ffloat-store -o gcctest.exe gcctest.c -lm ; gcctest.exe
1234567.2-1234567.1: d = 0.1
12345678.2-12345678.1: d = 0.1
123456789.2-123456789.1: d = 0.0999997
1234567891.2-1234567891.1: d = 0.0999979
12345678912.2-12345678912.1: d = 0.100002
123456789123.2-123456789123.1: d = 0.100002
1234567891234.2-1234567891234.1: d = 0.100916
12345678912345.2-12345678912345.1: d = 0.0868587
123456789123456.2-123456789123456.1: d = 0.000198364
1234567891234567.2-1234567891234567.1: d = -0.0303955
12345678912345678.2-12345678912345678.1: d = -0.0839844
123456789123456789.2-123456789123456789.1: d = -7.95312

SPARC/Solaris9/gcc-3.4.2
% rm gcctest.exe ; gcc -O -ffloat-store -o gcctest.exe gcctest.c -lm ; gcctest.exe
OR
% rm gcctest.exe ; gcc -O -ffloat-store -o gcctest.exe gcctest.c -lm ; gcctest.exe
1234567.2-1234567.1: d = 0.1
12345678.2-12345678.1: d = 0.1
123456789.2-123456789.1: d = 0.0999997
1234567891.2-1234567891.1: d = 0.099998
12345678912.2-12345678912.1: d = 0.100002
123456789123.2-123456789123.1: d = 0.100006
1234567891234.2-1234567891234.1: d = 0.10083
12345678912345.2-12345678912345.1: d = 0.0859375
123456789123456.2-123456789123456.1: d = 0
1234567891234567.2-1234567891234567.1: d = 0
12345678912345678.2-12345678912345678.1: d = 0
123456789123456789.2-123456789123456789.1: d = 0

Any comments?

Lester


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]