[comp.lang.c] ANSI float.h

m5@lynx.uucp (Mike McNally) (01/17/89)

The new K&R almost-ANSI book has a little section in the back that describes 
the contents (well, part of the contents, apparently) of <float.h>.  I am
confused by some of the "minimum magnitude" values listed:

FLT_EPSILON 1e-5        Isn't that kind of big?  With IEEE single-precision,
                        the actual value according to the definition should
                        be something like 5.4e-8.

FLT_MIN     1e-37       Does this mean that an ANSI-compliant compiler
                        does not need to supply negative float values
                        beyond a negative itsy-bitsy value?  Does it
                        make sense that coding x=-2.0 results in a 
                        non-portable program?

I suppose I can live with FLT_EPSILON, but FLT_MIN bothers me.  Shouldn't
that be more like -1e37?

-- 
Mike McNally                                    Lynx Real-Time Systems
uucp: {voder,athsys}!lynx!m5                    phone: 408 370 2233

            Where equal mind and contest equal, go.

gwyn@smoke.BRL.MIL (Doug Gwyn ) (01/18/89)

In article <5186@lynx.UUCP> m5@lynx.UUCP (Mike McNally) writes:
>The new K&R almost-ANSI book has a little section in the back that describes 
>the contents (well, part of the contents, apparently) of <float.h>.  I am
>confused by some of the "minimum magnitude" values listed:

K&R2 in many instances replaced the pedantic wording of the proposed
ANSI Std X3.159 with simpler, although less precise, wording, presumably
in an attempt to be more readily understood by the book's target
readership.

The X3.159 definitions are, I think, correct.  K&R2 is misleading.
(Of course, so were earlier X3.159 drafts that K&R2 was based on.)

>FLT_EPSILON 1e-5        Isn't that kind of big?  With IEEE single-precision,
>                        the actual value according to the definition should
>                        be something like 5.4e-8.

The X3.159 definition of *_EPSILON is "the difference between 1.0 and
the least value greater than 1.0 that is representable in the given
floating point type".  FLT_EPSILON is required to be at most 1E-5.
The proper value for an implementation that also conforms to ANSI/IEEE
Std 754-1985 (which is NOT required by X3.159) would be 1.19209290E-07F.

>FLT_MIN     1e-37       Does this mean that an ANSI-compliant compiler
>                        does not need to supply negative float values
>                        beyond a negative itsy-bitsy value?  Does it
>                        make sense that coding x=-2.0 results in a 
>                        non-portable program?

The X3.159 definition of *_MIN is "minimum normalized positive floating-
point number".  FLT_MIN is required to be at most 1E-37.  The proper
value for IEEE 754 (NOT required by X3.159) would be 1.17549435E-38F.