The strange phenomenon of two floats added ~ ~ ~
PHP Code
List ($usec, $sec) = Explode (", microtime ());p rintf (" s:%.16f ", (float) $sec);p rintf (" microseconds:%.16f ", (float) $usec);p rint F ("Add:%.16f", (float) $usec + (float) $sec);
The output is:
Seconds: 1327048300.0000000000000000
Microseconds: 0.9687510000000000
Add: 1327048300.9687509536743164
I know that the float is an approximation, but I'm printing $usec and keeping 16 digits after the decimal point, does it have a decimal number? Doesn't that mean it's equal to 1327048300?
Why isn't it 1327048300.9687510000000000 when it's two added??
Thank you!!
------Solution--------------------
Warning
Floating point Accuracy
It is obvious that a simple decimal score like 0.1 or 0.7 cannot be converted to an internal binary format without losing a little bit of precision. This can result in confusion: for example, floor ((0.1+0.7) *10 typically returns 7 instead of 8 as expected because the internal representation of the result is actually similar to 7.9999999999 ....
This is related to the fact that it is impossible to accurately express certain decimal fractions with a finite number of digits. For example, the decimal 1/3 becomes 0.3333333. . .。
So never believe that the floating-point number is accurate to the last one, and never compare two floating-point numbers for equality. If you do need a higher precision, you should use any mathematical or GMP function with any precision.
------Solution--------------------
Even if it's not clear what a valid number is, I don't understand why your parents spend a lot of money on your college.