It isn't dangerous
, per se, but it is important to remember that floating point numbers are an approximation
to an exact value.
Since they are stored in a binary computer, some values cannot be exactly represented anyway. The example your teacher gave was 0.1. Remember, that is the same as one tenth, or 1/10. In binary, that fraction has an infinitely repeating sequence of digits after the decimal point.
Also, it essentially maps a very short sequence of digits/values (stored as an integer value) a specific distance from the decimal point. The idea, of course, is to represent the most significant values. You cannot, then, combine a very large value (like 1.234x
) with a very small value (like 1.234x
), since one of those value will essentially be lost. Guess which one it is? So no matter how many times I add the small value to the large, the large will never change.
There are other considerations as well. The way the value is handled by the computer hardware may change it in minor ways, etc.