Seungbeom Kim <(E-Mail Removed)> writes:

> On 2012-07-21 14:39, Tim Rentsch wrote:

>>

>> Because of the vagaries of how floating point is represented,

>> I believe it is possible in principle for 0.0 to be seen as

>> true (that is, != 0) in a conforming implementation, if that

>> implementation (a) does not have an exact FP representation for zero,

>> and (b) has implementation-defined rounding rules which are defined

>> suitably. AFAIK both (a) and (b) may be true in a conforming

>> implementation, that is, I don't know of any requirement that

>> prevents the possibility of either (or of both together).

>

> Even if it's possible that there isn't an exact representation for zero

> and that '0.0' has to be represented as a non-zero, won't '0.0 == 0'

> still be true because the right-hand side has to be converted to the

> same non-zero FP value first? Then, the value of (bool)0.0, assuming

> it is defined as '0.0 != 0', should be false as well.

> In that case, the non-zero value may behave effectively as a substitute

> for zero, or an "acting" zero, except that it might not print out as

> an exact zero (just as an acting president doesn't look like the real

> president, though having the same power ).
The test involved in a conditional expression is whether the value of

the first expression "compares equal to zero". It's not absolutely

clear to me that this is intended to mean "exp == 0" or not (i.e. to

reference the semantics of the -- operator), but I can't think of any

better meaning.

That aside, 0.0 == 0 is interesting. On a machine that has an exact

floating zero, 0 must convert to it, but 0.0 need not (surely this is

unintended?). On one that does not have an exact floating zero, very

similar wording is used in 6.3.1.4 p2 (for the conversion) as is used in

6.4.4.2 p3 (for the representation of the constant):

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

"the result is either the nearest higher or nearest lower

representable value, chosen in an implementation-defined manner"

but there's nothing to say that the implementation must choose in the

same way in both cases. A perverse implementation could "round" 0.0 up

and convert 0 by going the other way!

--

Ben.