Article View: comp.std.c
Article #1358Re: Questions about NCEG
From: diamond
Date: Fri, 01 Jun 1990 04:02
Date: Fri, 01 Jun 1990 04:02
34 lines
2437 bytes
2437 bytes
In article <15570@bfmny0.BFM.COM> tneff@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@tkou02.enet.dec.com Proposed group comp.networks.load-reduction: send your "yes" vote to /dev/null.
Technical Details
Message-ID:
<1757@tkou02.enet.dec.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!decuac!shlump.nac.dec.com!tkou02.enet.dec.com!diamondReferences:
<3094@goanna.cs.rmit.oz.au> <1990May29.193451.6533@twinsun.com> <13016@smoke.BRL.MIL> <1990May30.203146.11442@twinsun.com> <15570@bfmny0.BFM.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!decuac!shlump.nac.dec.com!tkou02.enet.dec.com!diamond From: diamond@tkou02.enet.dec.com (diamond@tkovoa) Newsgroups: comp.std.c Subject: Re: Questions about NCEG Message-ID: <1757@tkou02.enet.dec.com> Date: 1 Jun 90 04:02:36 GMT References: <3094@goanna.cs.rmit.oz.au> <1990May29.193451.6533@twinsun.com> <13016@smoke.BRL.MIL> <1990May30.203146.11442@twinsun.com> <15570@bfmny0.BFM.COM> Reply-To: diamond@tkou02.enet.dec.com (diamond@tkovoa) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 34