v3x = v1x + v2x;

and

v1x=-2

v2x=2

then my compiler tells me that v3x = -0 but i think it must be 0

!!??

Dunno about this one. Maybe because you added to a negative number and the

result was not greater than zero, the result was negative zero rather than

positive zero?

and my second problem is:

how to check if something like this happens ?if (v3x = -0) doesn’t work !!!

and a check for (v3x = 0) does the same

damn

In this example you used = instead of == and the value of v3x = 0 would be

zero, i.e. false. (I think this is true even though we’re dealing with

floating-point values, but I haven’t checked so please feel free to correct

me on that.)

But testing two floating-point values for equality is rarely a good idea

anyway since it’s likely that the computer can’t represent the value

exactly. (The way I understand it, it might not even be able to even if it

could represent it exactly as an integer.) In this particular case it might

work since 0, -0, 2 and -2 all have exact representations according to the

IEEE standard, but in general it should be much safer to test if the

difference between them is “small enough”.

Torbj?rn Andersson

References:

http://www.sns.ias.edu/Main/computing/compilers_html/common-tools/numerical_

comp_guide/index.html