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]

exp() bug?


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 cygtest.c:
    ------------8<------------ top cut -> bottom ------------->8------------
/*
 * rm cygtest.exe; gcc -O -mno-cygwin -o cygtest.exe cygtest.c -lm; cygtest.exe
 * rm cygtest.exe; gcc -O -o cygtest.exe cygtest.c -lm; cygtest.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 cygtest.exe ; gcc -O -mno-cygwin -o cygtest.exe cygtest.c -lm; cygtest.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 cygtest.exe ; gcc -O -o cygtest.exe cygtest.c -lm; cygtest.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 cygtest.exe ; gcc -O -o cygtest.exe cygtest.c -lm ; cygtest.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 cygtest.exe ; gcc -O -o cygtest.exe cygtest.c -lm ; cygtest.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]