MINFLOAT
Rodney Hoinkes
rodney at dgp.toronto.edu
Wed Aug 1 02:19:47 AEST 1990
I have been working with a routine in which I need to
determine whether a variable is out of the bounds of a
float (NaN etc.), so I have been trying to check it
against MINFLOAT and MAXFLOAT as defined in values.h.
If I check
if(val > MAXFLOAT) ... this works fine for NaN
problems
BUT!
if val = 0.0, and I do the following
if(val < MINFLOAT) ... it tells me that val IS
less than MINFLOAT
The test program below shows this simply:
#include <stdio.h>
#include <values.h>
#define ZERO 0.0
main() {
printf("MINFLOAT %g ZERO %g\n",MINFLOAT,ZERO);
if(ZERO < MINFLOAT)
printf("ZERO is less than MINFLOAT\n");
else
printf("ZERO is greater than MINFLOAT\n");
}
compiled with cc test.c -lc_s -o test
I get the following output:
MINFLOAT 1.4013e-45 ZERO 0
ZERO is less than MINFLOAT
Can anyone explain? If I printf %f they both return 0.00000
or whatever.
--
Rodney Hoinkes
Centre for Landscape Research
University of Toronto
CANADA
rodney at dgp.toronto.edu
More information about the Comp.sys.sgi
mailing list