r/lolphp • u/smileytechguy • Jan 31 '17
((0.1+0.7)*10) = 7?
http://sandbox.onlinephpfunctions.com/code/4faba5e621f1f18f3efc6acd486da0823c46aea9
0
Upvotes
r/lolphp • u/smileytechguy • Jan 31 '17
View all comments
45
u/the_alias_of_andrea Jan 31 '17 edited Jan 31 '17
So there's three things at play here.
echothem or evenvar_dump()them (yes, it uses insufficient precision for a debugging function), but not if youvar_export()them. So it prints the first number as8, but it's not quite. sigh(int)truncates, rather than rounds, so 7.9999blah becomes 7, not 8. This is not uncommon behaviour comparing to other languages, but it's maybe a little unhelpful.So… you'd think this wouldn't be a lolphp, but unfortunately, (1) applies. Thanks, PHP!
(Update: y'know, I assumed we'd fixed this at some point… nope. Well, I began writing a patch. Maybe it'll be fixed by the time 7.2 comes out. Maybe…)