June 18, 2013

Post: PHP vs. BIGINT vs. float conversion caveat

… see float to string conversion is not portable across systems and PHP versions. So if you’re handling large numbers stored as float (especially on 32-bit systems where 32-bit int overflow will implicitly convert to float) and getting strange bugs, remember that string conversion

Comment: PHP vs. BIGINT vs. float conversion caveat

… different thing – conversion from string. First of all, I don’t see any strings there. I can see a float converted to a string in 2… thing: even though PHP tries to handle this in a crossplatform way (because it uses its own float-to-string and string-to-float utilities since 5.2…

Comment: PHP vs. BIGINT vs. float conversion caveat

… see any strings there. Peter just made a typo. I explicitly mentioned conversion TO string, in bold. > in both cases float is expected to lose its…) INTEGER values MUST be stored without ANY precision loss. > PHP tries to handle this in a crossplatform way Even though it tries… perfectly valid solution in some scenarios. It’s only the float to string conversion which suddenly, and unexpectedly, fails.

Post: Handling big result sets

…loop mysql_fetch_array (here I use PHP functions but they are common or …default NULL, `f11` int(11) default NULL, `f12` float default NULL, `f13` int(11) default NULL, `…to convert millions of values from int to the string and client has to do reverse conversion. This takes time. Furthemore string

Comment: PHP vs. BIGINT vs. float conversion caveat

The problem with PHP (or its documentation) is intimate behavior details are not described and assumptions can be wrong. If conversion of floats to strings is not designed to be predictable it would be good to say it is platform and/or version dependent.