[JW] fp constant and the representable range

[JW] fp constant and the representable range

Post by Jun Woon » Wed, 01 Dec 2004 06:30:03


[In this question I don't want to consider the properties specific to
IEEE 754 and mean to be general as much as possible. And this
question arises when reading the answer to C90 DR025.]

Suppose an implementation that issues no diagnostic even when meets
a fp constant like 9e9999 which is greater than DBL_MAX because it
defines the range of representable values for double as from -infinity
to infinity. Is this implementation conforming? Note, according to the
standard, that the positive infinity does not qualify as /type/_MAX
since it is not a fp number. So in other words, should the range of
representable values for the fp types be from -/type/_MAX to
/type/_MAX inclusive? The relevant wording seems to say yes:

5.2.4.2.2p9
- maximum representable finite floating-point number ...
~~~~~~~~~~~~~

6.4.4p2 (constraints)
The value of a constant shall be in the range of representable
~~~~~~~~~~~~~
values for its type.

Is this interpretation correct?


Thanks in advance.
 
 
 

[JW] fp constant and the representable range

Post by Fred J. Ty » Wed, 01 Dec 2004 09:24:59


Yes. If the implementation defines the range of representable values
as -infinity to +infinity, then all values are representable. Some
values convert exactly to a machine representation, other values
convert to a machine representation that is approximately equal to
the value (so is an inexact conversion).


Not if -infinity and +infinity are valid machine representations.


There are three cases to consider:
0.1 value between DBL_MIN and DBL_MAX
1e-99999 value between zero and DBL_MIN
9e+99999 value between DBL_MAX and infinity

All three cases are not exactly representable (assumes non-decimal
FLT_RADIX).
All three numbers are bounded by a pair of machine representations.
---
Fred J. Tydeman Tydeman Consulting
XXXX@XXXXX.COM Testing, numerics, programming
+1 (775) 358-9748 Vice-chair of J11 (ANSI "C")
Sample C99+FPCE tests: http://www.yqcomputer.com/
Savers sleep well, investors eat well, spenders work forever.