Document: WG14 N1320
Submitter: Fred Tydeman (USA)
Submission Date: 2008-07-13
Related WG14 documents: C89 Defect Report 25
Subject: Integrating C89 Defect Report 25 into C1x
One of the more contensious issues I have had with compiler implementors is the meaning of "range of representable values for its type" as used in C for floating-point. Some vendors consider the floating-point constant 1e-9999999 (the underflow case) and 1e+9999999 (the overflow case) as outside the range of representable values and issue a translation time diagnostic (as per the constraint in 6.4.4 Constants) that ends translation. They claim the valid range of values (for double) is -DBL_MAX thru -DBL_MIN, zero, and DBL_MIN thru DBL_MAX (even though the hardware supports signed subnormal values and signed infinity).
Defect report 25 against C89 was not incorporated into C99 (I believe that this was an oversight). The relavent parts of the committee response are principals 7 and 8:
7. There may be minimum and/or maximum
exactly-representable values; all values between and
including such extrema are considered to ``lie within the
range of representable values.''
8. Implementations may elect to represent ``infinite''
values, in which case all real numbers would lie within the
range of representable values.
Basiclly, a given real value is one of:
126.96.36.199 strtod() functions, paragraph 10, implies that outside the range is only the overflow case, as the underflow case is mentioned as a seperate case. It also implies that values between largest finite representable and infinity are outside the range. If the representable range is all real numbers, then the "overflow" case will not cause errno be become ERANGE.
Proposed changes to C1x
Add to 188.8.131.52.2 <float.h>, a new paragraph after #3:
The minimum range of representable values is -maximum representable finite floating-point number thru +maximum representable finite floating-point number in each type. In addition, if -infinity is representable (in a type), the range is extended (for that type) to all negative real numbers, and if +infinity is representable (in a type), the range is extended (for that type) to all positive real numbers.
Change 184.108.40.206 strtod functions, paragraph 10 in Returns: 'correct value is outside the range of representable values' --> 'result overflows (7.12.1)'.
Change 220.127.116.11.1 wcstod functions, paragraph 10 in Returns: 'correct value is outside the range of representable values' --> 'result overflows (7.12.1)'.
Add to Annex F, at the end of paragraph 1:
'Since -infinity and +infinity are representable in IEC-60559 formats, all real numbers lie within the range of representable values.'
Add to Rationale (or standard?) for 18.104.22.168.2:
Principles for C floating-point representation:
(These principles are intended to clarify the use of some terms in the standard; they are not meant to impose additional constraints on conforming implementations.)
(Points 3 and 4 are meant to apply to representations of the same floating type, not meant for comparison between different types.)
This implies that a conforming implementation is allowed to accept a floating-point constant of any arbitrarily large or small value.