m5@lynx.uucp (Mike McNally) (01/19/89)
The <float.h> file of the ANSI library contains two constants, FLT_EPSILON and DBL_EPSILON. These are (according to K&R II) supposed to be the smallest x such that 1.0 + x != 1.0. Should I interpret this as: The smallest x such that the statement i = (1.0 + x != 1.0); assigns 1 to the variable i. or should it be: The smallest x such that the sequence: val1 = 1.0; val2 = 1.0 + x; i = val1 != val2; results in assignment of 1 to the variable i. Seems to me that there is a difference, because intermediate results during expression evaluation may involve greater precision than available for storage of values. On a related note, the qualification that x be the "smallest" value bothers me: shouldn't x be positive? Most likely the actual ANSI draft is more specific; it probably clears up the first question as well. -- 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/19/89)
In article <5198@lynx.UUCP> m5@lynx.UUCP (Mike McNally) writes: >The <float.h> file of the ANSI library contains two constants, FLT_EPSILON >and DBL_EPSILON. These are (according to K&R II) supposed to be the >smallest x such that 1.0 + x != 1.0. ... Funny, this question just came up a couple of days ago (perhaps in comp.std.c). The actual wording in the proposed Standard is "the difference between 1.0 and the least value greater than 1.0 that is representable in the given floating point type" with the formula for the floating point model given for clarification: b^(1-p). >Seems to me that there is a difference, because intermediate results during >expression evaluation may involve greater precision than available for >storage of values. Yes, that's permitted. The *_EPSILON constant applies to the storage representation for the floating-point types, which is often narrower than the representation used within a floating point arithmetic register. Reminder: This is my interpretation, not an official pronouncement.