Mail Archives: djgpp/1993/04/06/04:29:07
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. It seems the
compiler has rather inaccurate (and inconsistent) mapping
between decimal and binary floating point constants. This
causes a particularly bad error when using the value
MAXDOUBLE.
for example :
---------------------- cut here --------------------------
/* use the value in include/values.h of djgpp 1.09 */
#define MAXDOUBLE 1.79769313486231570e+308
double dd = MAXDOUBLE;
main()
{
printf("MAXDOUBLE = %.20e, dd = %.20e\n",MAXDOUBLE,dd);
if (dd > MAXDOUBLE)
printf("ERROR: dd > MAXDOUBLE\n");
if (dd < MAXDOUBLE)
printf("ERROR: dd < MAXDOUBLE\n");
if (MAXDOUBLE > dd)
printf("ERROR: MAXDOUBLE > dd\n");
if (MAXDOUBLE < dd)
printf("ERROR: MAXDOUBLE < dd\n");
}
---------------------- cut here --------------------------
Compile this and run it, and you'll notice that
MAXDOUBLE != MAXDOUBLE != 1.79769313486231570e+308
This may well be a generic bug in the version of gcc used,
but I will leave it to those who know more about gcc to look
into it.
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.
Graeme Gill.
- Raw text -