Try this on Windows
- Open Calculator directly or by typing calc in RUN.
- Then type 4 and take square root "sqrt"
- And whatever you get(ideally you will get 2!), substract 2 from it.
Now My Question is, is this mathematically right ??
Ideally not right, but the way floating point number are represented inside computer would result in such unexpected answer.
If you look into the numerical value of the answer, it is very close to 0, that is the expected answer.
it is giving -8.1648465955514287168521180122928e-39
which is basically = 0 as it have 10^-39...
|show 1 more comment|
No, it's not mathematically right. 2-2 = 0 :)
Calc is giving is -0.0000000000000000001, which means the sqrt function yielded a number very close to 2, but which had some tiny fractional portion rounded off for display purposes. When you subtract 2, you get a number which is very close to 0, but not quite.
It's an artifact of how floating point numbers are stored in a computer. Every (non symbolic) calculator will have some problems that produce incorrect results like that. For instance, try (sqrt(pi))^2-pi, which should be 0. I just tried it in this online calculator and got -1.3691388027.