Document: WG14 N1320


Integrating C89 Defect Report 25 into C1x


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:

7.20.1.3 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 5.2.4.2.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 7.20.1.3 strtod functions, paragraph 10 in Returns: 'correct value is outside the range of representable values' --> 'result overflows (7.12.1)'.

Change 7.24.4.1.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 5.2.4.2.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.)

  1. ``Value'' refers to the abstract (mathematical) meaning; ``representation'' refers to the implementation data pattern.
  2. Some (not all) values have exact representations.
  3. There may be multiple exact representations for the same value; all such representations shall compare equal.
  4. Exact representations of different values shall compare unequal.
  5. There shall be at least one exact representation for the value zero.
  6. Implementations are allowed considerable latitude in the way they represent floating-point quantities; in particular, as noted in Footnote 10 on page 14, the implementation need not exactly conform to the model given in subclause 5.2.4.2.2 for ``normalized floating-point numbers.''
  7. There may be maximum negative and/or maximum positive 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.
  9. For a given value, the ``nearest representable value'' is that exactly-representable value within the range of representable values that is closest (mathematically, using the usual Euclidean norm) to the given value.

(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.