I know that using ==
to check equality of floating-point variables is not a good way. But I just want to know that with the following statements:
Yes, y
will assuredly take on the value of x
:
[expr.ass]/2: In simple assignment (=), the object referred to by the left operand is modified ([defns.access]) by replacing its value with the result of the right operand.
There is no leeway for other values to be assigned.
(Others have already pointed out that an equivalence comparison ==
will nonetheless evaluate to false
for NaN values.)
The usual issue with floating-point ==
is that it's easy to not have quite the value you think you do. Here, we know that the two values, whatever they are, are the same.