Edit report at http://bugs.php.net/bug.php?id=51396&edit=1
ID: 51396 Comment by: codeslinger at compsalot dot com Reported by: codeslinger at compsalot dot com Summary: Math is Unreliable Status: Feedback Type: Bug Package: Math related Operating System: any PHP Version: Irrelevant Assigned To: aharvey New Comment: String conversion errors There is a flag called $FloatType You can use it to select the type of conversion that is done. //this fails with string conversion error case 0: $s = (string)$f; //this fails with string conversion error case 12: $s = is_float($f) ? sprintf('%.12F', $f) : (string)$f; //this fails with string conversion error case 14: $s = is_float($f) ? sprintf('%.14F', $f) : (string)$f; //this WORKS, does not cause a string conversion error case 20: $s = is_float($f) ? sprintf('%.20F', $f) : (string)$f; When I say conversion error, I mean that the result is "0.0:" not that php gives any kind of error message. Previous Comments: ------------------------------------------------------------------------ [2010-03-26 10:23:27] codeslinger at compsalot dot com quote: Btw, it could be due to bad initialized data as well I don't understand the question/statement. The program generates all of it's data. If you look near the bottom of pov.pco.php you will see the following line: echo "FATAL ERROR: PHP Math is Corrupt Again!!! idx = $idx\n"; If you set a breakpoint there in a php debugger and examine the vaules you will see that that array contains a float of 0.1 and that the string it was converted to is "0.0:" ------------------------------------------------------------------------ [2010-03-26 10:17:47] codeslinger at compsalot dot com Thank You for the response. This program executes thousands of identical loops it performs a number format conversion on each of those thousands of numbers in it's array. Out of all of those thousands of identical conversions about 4 of them will produce an invalid result. for this specific program, if I skip the array_merge (see $Nest) then the bug does not occur. Every time I make a change to the loops etc. the behavior changes, even to where the bug is not triggered. I have already simplified this program quite a bit and the result was that it now fails at a totally different array index then when I first observed the problem. The trigger is very finicky. XP is not a factor here, even though the original problem was found on XP, I am running this Snowflake program on Ubuntu Linux. converting a number to a string should never result in that string containing a non-numeric character. I can try to reduce this program further, but really and truly, it is hard to trigger this -- but once triggered it is totally consistent and repeatable. ------------------------------------------------------------------------ [2010-03-26 10:11:25] paj...@php.net Btw, it could be due to bad initialized data as well (as you experience it on unix as well). Can you try to run your script under valgrind too? ------------------------------------------------------------------------ [2010-03-26 09:54:33] paj...@php.net It looks to me in a bug at the number formatting in the Windows API (not php dependent). Other users met this problem on old XP systems. You could reproduce it using number_format only. Or maybe only with a single printf function. Can you try using another windows box or using 5.3.2-vc9 builds? Btw, it is not about bad or good attitude but about having something we can actually use to help you. I can understand your worries after having spent hours to debug this problem, but we will still use a small script to debug this problem, if any. ------------------------------------------------------------------------ [2010-03-26 09:40:23] codeslinger at compsalot dot com did you even LOOOKK at the script that I provided? it is not that complicated. a few loops and some array allocations. previous attempts to reduce this to anything simpler have been unsuccessful. this is exactly the attitude that causes me to be overwrought. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/bug.php?id=51396 -- Edit this bug report at http://bugs.php.net/bug.php?id=51396&edit=1