delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/10/05/11:36:13

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Tue, 5 Oct 2004 08:35:56 -0700
From: Lester Ingber <ingber AT ingber DOT com>
To: cygwin AT cygwin DOT com
Subject: exp() bug?
Message-ID: <20041005153556.GA712@ingber.com>
Mime-Version: 1.0
User-Agent: Mutt/1.4.1i

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019