Topic: Equalities of doubles
Author: kanze@us-es.sel.de (James Kanze)
Date: 18 Nov 93 14:29:55 Raw View
In article <CGnttn.2o@cbnewse.cb.att.com> grumpy@cbnewse.cb.att.com
(Paul J Lucas) writes:
|> From article <2ce2sf$dmo@csi.jpl.nasa.gov>, by smyth@Jpl.Nasa.Gov (Mike M. Smyth):
|> > I have a question for language lawyers. Is it required that the following code
|> > double y=some_value;
|> > double x=y;
|> > if(x ==y)
|> > cout<<"TRUE";
|> > always prints TRUE?
|> I would be surprised if the answer were not yes.
Although I cannot find a quote to back me up, I would suppose that
*assignment* between two things of the same type may never involve
value change.
Actually, it is rather strange that the standard does not say anything
about this. To quote ISO 9899 (section 6.3.5), for example: "the
result of the / operator is the quotient from the division of the
first operant by the second." There is a paragraph to explain what
happens when integers are divided, and the result is not exact. What
is the absence of such a paragraph for floating point values supposed
to mean? That the results must be exact, ie: 1.0/3.0 must result in
one third (and no conforming implementation is possible on a finite
machine), or that there are no constraints on the precision, and a
machine that returns 0.0 (or 1.0, or even 1000.0) for 1.0/3.0 would be
conforming.
I would expect that the intent is that the result be either the
nearest higher or the nearest lower representable value, but I could
find no words in the standard to support my view. (The closest I
could come is in 6.2.1.4, but this only talks of converting one
floating point type to a narrower one.)
Follow-ups to comp.std.c.
--
James Kanze email: kanze@us-es.sel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung