Questions about NCEG

diamond@tkovoa diamond at tkou02.enet.dec.com
Fri Jun 1 14:02:36 AEST 1990


In article <15570 at bfmny0.BFM.COM> tneff at bfmny0.BFM.COM (Tom Neff) writes:

>ANSI C does require that the strings "-0.0" and "0.0" parse to the same
>internal representation number

The closest I can find is the "Semantics" section of 3.1.3.1:
"If the scaled value is in the range of representable values (for its
type) the result is either the nearest representable value, or the
larger or smaller representable value immediately adjacent to the
nearest representable value, chosen in an implementation-defined manner."

No rule is made for choosing which of two nearest representable values
should be chosen.  No rule suggests choosing an EQUAL representable value
immediately addjacent to the nearest representable "value" (values?).

Hmm.  If the implementation so defines, then parsing 2.0 gives a result of
2.0, 2.0 plus some epsilon, or 2.0 minus some (possibly different) epsilon,
that is, the larger or smaller immediately adjacent to the nearest.

The results of floating-point arithmetic are not required to be even this
accurate.  For example, 2.0 + 2.0 is allowed to yield 4.5 even if there
exist representations for 4.1 and 4.4.

I think this means that if your parser is coded in ANSI C, it might not
be an ANSI parser.  You think you're parsing floating-point constants,
but you're not doing a good enough job of accuracy!  A machine-dependent
parser can do it by doing calculations in ints, playing with the bits
of some ints and unioning those to a float.  (Whew!  For a moment, I
thought that an ANSI C compiler couldn't be coded in ANSI C.  It still
can be, but just not portably.)

-- 
Norman Diamond, Nihon DEC     diamond at tkou02.enet.dec.com
Proposed group comp.networks.load-reduction:  send your "yes" vote to /dev/null.



More information about the Comp.std.c mailing list