|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-03-19 12:11 UTC] codeslinger at compsalot dot com
Description: ------------ It is with great hesitancy that I enter this bug, because I am not able to produce a simple test case for it. But the bug is very serious. I have a program that calculates and sends out customer statements. Without making any changes to the php program itself which has been running fine, I upgraded to PHP 5.2.9 and also tested with 5.2.9-1 both with and without xdebug enabled. The math is bad, the calculations are incorrect. Below is a program that displays this problem, but it does not fail when run stand-alone, this program only fails when run inside of the billing program's context where it is calculating the statement balances. The billing program of course does a billion things before it gets to this point. But at that point the math behavior of PHP is corrupt. Wrong math results are the only visible sign of the problem, the program runs to completion and prints the statements etc. The program reads the numbers from a database as strings and converts them to floats to do the totals. This is not a case of loss of precision, as I said the program runs fine on 5.2.5. But sprintf will convert "19.000000" to = 18:0 Note the colon, I'm using the default language settings of USA English. Probably related to Bug #47304 Reproduce code: --------------- <?php //I ran a series of tests all of them failed, //it was totally consistent and reproducible. //Here are the most interesting tests/results. $arrMsgs = array(); //for the sake of completeness, I also added this, //it made no difference $arrMsgs[] = "Locale = ".setlocale(LC_ALL, "english-usa"); $arrMsgs[] = "memory_get_peak_usage(true) = ". memory_get_peak_usage(true); $arrMsgs[] = "memory_get_peak_usage(false) = ". memory_get_peak_usage(false); $arrMsgs[] = "memory_get_usage(true) = ". memory_get_usage(true); $arrMsgs[] = "memory_get_usage(false) = ". memory_get_usage(false); $arrMsgs[] = "(float)19.000000 = ".(float)19.000000; $arrMsgs[] = "(float)'19.000000' = ".(float)'19.000000'; $arrMsgs[] = "round('19.000000', 2) = ".round('19.000000', 2); print_r($arrMsgs); ?> Expected result: ---------------- when I run this program on PHP 5.2.5 I get the following result [DebugInfo] => Array ( [0] => memory_get_peak_usage(true) = 3932160 [1] => memory_get_peak_usage(false) = 3731872 [2] => memory_get_usage(true) = 3932160 [3] => memory_get_usage(false) = 3589320 [10] => (float)19.000000 = 19 [11] => (float)'19.000000' = 19 [12] => round('19.000000', 2) = 19 ) Actual result: -------------- [DebugInfo] => Array ( [0] => memory_get_peak_usage(true) = 3932160 [1] => memory_get_peak_usage(false) = 3732128 [2] => memory_get_usage(true) = 3932160 [3] => memory_get_usage(false) = 3589216 [10] => (float)19.000000 = 18.: [11] => (float)'19.000000' = 18.: [12] => round('19.000000', 2) = 18.: ) notice the colons following the numbers, I did not add those, it is part of the failure. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 18:00:01 2025 UTC |
I'm not sure what's wrong. Here is what I get: Windows 2008 (latest SP): Array ( [0] => Locale = English_United States.1252 [1] => memory_get_peak_usage(true) = 262144 [2] => memory_get_peak_usage(false) = 58240 [3] => memory_get_usage(true) = 262144 [4] => memory_get_usage(false) = 57240 [5] => (float)19.000000 = 19 [6] => (float)'19.000000' = 19 [7] => round('19.000000', 2) = 19 ) Windows 2003 (latest SP): Array ( [0] => Locale = English_United States.1252 [1] => memory_get_peak_usage(true) = 262144 [2] => memory_get_peak_usage(false) = 56152 [3] => memory_get_usage(true) = 262144 [4] => memory_get_usage(false) = 56024 [5] => (float)19.000000 = 19 [6] => (float)'19.000000' = 19 [7] => round('19.000000', 2) = 19 ) Windows XP sp2: Array ( [0] => Locale = English_United States.1252 [1] => memory_get_peak_usage(true) = 262144 [2] => memory_get_peak_usage(false) = 57112 [3] => memory_get_usage(true) = 262144 [4] => memory_get_usage(false) = 56112 [5] => (float)19.000000 = 19 [6] => (float)'19.000000' = 19 [7] => round('19.000000', 2) = 19 )