int s = (.7 * 3) + (.3 * 3) is 2 ?

Started by
60 comments, last by Zahlman 19 years, 8 months ago
I just have to add that there are often compiler settings that effect the results of floating point operations and that printf should never be trusted since it might very well not print the data in the format you expect. Also, there is no point in comparing code if it's later compiled with different compilers or with different settings.

...and it's best to always avoid converting from float or double to int for many reasons, precision is one.
Advertisement
Quote:
Found on wiki:

A Russian gentleman on comp.lang.java.programmer, answering a question about floating point maths:

forget everything from school -- you are programmer,
and here 2.1*3.6=7.559995
but sometimes (2.1*3.6==7.559995)!=true
this is the world with no rules after point -- this is computer.

This topic is closed to new replies.

Advertisement