Subject: cygwin-b20 gcc: "A - floor(A)" returns a negative value
From: [email-masked] (Peter Kabal)

9 Nov 1998 04:49:48 -0800
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
To: <[email-masked]>

Switching from cygwin-b19 to cygwin-b20 caused a C-routine to give
incorrect results.  This was traced to a calculation (in double) of
"A - float(A)" which returns a negative value.  By definition it should
always be positive.  A short test program which demonstrates this
problem is included.  If the program is further simplified, the problem
goes away.  To exercise the bug, the program must be compiled with
optimization level -O3.

% gcc -O3 tfloor.c -o tfloor
% ./tfloor
AV = 20, AV - floor(AV) = -1.11022e-15

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

int
main (argc, argv)
     int argc;
     char *argv[];
{
  double AV;

  AV = 0.05;
  AV = 1.0 / (AV - floor (AV));
  printf ("AV = %g, AV - floor(AV) = %g\n", AV, AV - floor(AV));

  return 0;
};
----------------
Peter Kabal    [email-masked]
Dept. Electrical & Computer Engineering
McGill University
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".