tatiang
February 4, 2022, 7:52am
10
It’s not working correctly in all cases.
For example, it shows 343 as not being a perfect cube. There’s a rounding error… if you display the value of app variable perfect cube
, it’s 6.999999999 which is then considered not whole.
These topics discuss the problem:
Still don’t really get this:
In JavaScript, all numbers are floating-point numbers, so when we write expressions like 0.1 + 0.2 , it’ll return some numbers that we don’t expect like 0.30000000000000004 .
0.1 and 0.2 are approximated to their true values. The approximated value of 0.2 is larger than its rational equivalent, but the closest approximating of 0.3 is smaller than the rational number.
Then we end up with the sum of 0.1 and 0.2 is slightly larger than the rational number 0.3 becaus…