@thegoryone said in [php] Guess the output...:
And if that's not bad enough, comparing floats will cause you an entire planet of grief too if you don't do a bit of creative WTF'ing to work around the WTF. It's literally in the manual (FFS PHP).
php.net So never trust floating number results to the last digit, and do not compare floating point numbers directly for equality. If higher precision is necessary, the arbitrary precision math functions and gmp functions are available.
that's the same in any language though. the bit about floats and comparting for equality, or even trusting arbitrary lengths of decimal digits. If you need to trust an arbitrary number of decimal digits or need exact equality use a representation that gives that to you. Sure it makes them annoying to deal with but if it's important then pull up your big girl panties and just do it.
If on the other hand you are okay with accepting math that is precise, but the number of precise digits depends on the scale of the number. For standard floating point numbers you get about 6 decimal digits of precision, doubles get 15*. If you use IEEE floating point numbers you have to be okay with that level of imprecision (one part in 106 for floats or one part in 1015 for doubles), and you have to account for it in your comparisons.
That's not unique to PHP, though i'm sure PHP has plenty of its own WTFs when working with numbers.
i mean the whole if a string starts with adigit it must be a number for comparison "feature" must be only the tip of the iceberg.
* Floats have 6-7 significant digits depending on the scale of the number, double precision floatin point numbers get 15-16. that's how the IEEE spec works.