www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/04/06/12:29:07

From: Eric Backus <ericb AT lsid DOT hp DOT com>
Subject: Re: Bug in floating point constants
To: graeme AT labtam DOT labtam DOT oz DOT au
Date: Tue, 6 Apr 93 9:09:17 PDT
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Mailer: Elm [revision: 66.25]

Graeme Gill writes:
> 	I have discovered a bug in the handling of
> floating point constants that caused a significant error
> in a program I am trying to compile.
> 
> The workaround is to change line in include/values.h below
> #if defined(i396)
> 
> from 
> 
> #define MAXDOUBLE       1.79769313486231570e+308
> 
> to
> 
> #define MAXDOUBLE       1.79769313486231470e+308
>                                         ^ this digit changes.

I'm at work so I can't test your program on a PC.  For what it's
worth, I ran your test program on my workstation, and it works fine.

I'm responding to this because I believe that the existing value for
MAXDOUBLE is "correct" in that it reflects the correct maximum value
for 64-bit floating point numbers in IEEE format.  Rather than change
MAXDOUBLE, we really should figure out why this correct value is not
working properly, and fix that.  (Do you have a 486, a 386+387, or
386+emulator?  Maybe this is just an emulator bug.)

It would be interesting to look at the actual bit pattern that the
compiler is generating for these floating point numbers.  Here's a
program that would print it:


#define MAXDOUBLE       1.79769313486231570e+308
#define	ALMOSTMAX	1.79769313486231470e+308

double  dd = MAXDOUBLE;
double  ddd = ALMOSTMAX;

int
main()
{
    (void) printf("MAXDOUBLE = %.20e\n", MAXDOUBLE);
    (void) printf("ALMOSTMAX = %.20e\n", ALMOSTMAX);
    (void) printf("dd        = %.20e = 0x%8.8x 0x%8.8x\n",
		  dd, *(int *) &dd, *((int *) &dd + 1));
    (void) printf("ddd       = %.20e = 0x%8.8x 0x%8.8x\n",
		  ddd, *(int *) &ddd, *((int *) &ddd + 1));
}


On my (big endian) workstation, this prints:

MAXDOUBLE = 1.79769313486231570000e+308
ALMOSTMAX = 1.79769313486231470000e+308
dd        = 1.79769313486231570000e+308 = 0x7fefffff 0xffffffff
ddd       = 1.79769313486231470000e+308 = 0x7fefffff 0xfffffffa
--
				Eric Backus
				ericb AT lsid DOT hp DOT com
				(206) 335-2495

- Raw text -


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