Edit report at http://bugs.php.net/bug.php?id=53918&edit=1
ID: 53918 Updated by: cataphr...@php.net Reported by: exploringbinary at gmail dot com Summary: printf of floating point variable prints maximum of 53 decimal places -Status: Bogus +Status: Open Type: Bug Package: Math related Operating System: Windows (32-bit system) PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: Well, can't you just print the numbers in exponential format? A representation with more than 50 leading digits in the fractional part is not particularly useful. This seems a better option than showing > 53 digits of decimal places when the machine precision is of only 15.9546 decimal digits. I imagine the magic arbitrary 53 digits limits was because the precision of the machine precision of 53 binary digits, though this is of course irrelevant for decimal representations. Previous Comments: ------------------------------------------------------------------------ [2011-02-03 14:23:24] il...@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php 53 digits is the maximum limit enforced by most programming languages. http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by- language/ ------------------------------------------------------------------------ [2011-02-03 12:56:28] exploringbinary at gmail dot com Description: ------------ Bug #47168, "printf of floating point variable prints maximum of 40 decimal places", was not fixed as expected. Instead of the previous arbitrary limit of 40 digits, there is now an arbitrary limit of 53 digits. These three examples all print powers of two, which have exact representations in double-precision floating-point: <?php printf("%1.176f\n",1.044048714879763924273647057481047608912186281291034647641381832875155719135597796355663380296618925058282911777496337890625e-53); /* 2^-176 */?> <?php printf("%1.177f\n",5.220243574398819621368235287405238044560931406455173238206909164375778595677988981778316901483094625291414558887481689453125e-54); /* 2^-177 */?> <?php printf("%1.178f\n",2.6101217871994098106841176437026190222804657032275866191034545821878892978389944908891584507415473126457072794437408447265625e-54); /* 2^-178 */?> The output is: 0.00000000000000000000000000000000000000000000000000001 0.00000000000000000000000000000000000000000000000000001 0.00000000000000000000000000000000000000000000000000000 (The first prints 1 significant digit, the second rounds to 1 significant digit, and the third prints no significant digits.) Compare this to gcc C on Linux: printf("%1.176f\n",1.044048714879763924273647057481047608912186281291034647641381832875155719135597796355663380296618925058282911777496337890625e-53); /* 2^-176 */ printf("%1.177f\n",5.220243574398819621368235287405238044560931406455173238206909164375778595677988981778316901483094625291414558887481689453125e-54); /* 2^-177 */ printf("%1.178f\n",2.6101217871994098106841176437026190222804657032275866191034545821878892978389944908891584507415473126457072794437408447265625e-54); /* 2^-178 */ The output (which is correct) is: 0.00000000000000000000000000000000000000000000000000001044048714879763924273647057481047608912186281291034647641381832875155719135597796355663380296618925058282911777496337890625 0.000000000000000000000000000000000000000000000000000005220243574398819621368235287405238044560931406455173238206909164375778595677988981778316901483094625291414558887481689453125 0.0000000000000000000000000000000000000000000000000000026101217871994098106841176437026190222804657032275866191034545821878892978389944908891584507415473126457072794437408447265625 (I see that in formatted_print.c, #define MAX_FLOAT_PRECISION 40 was changed to #define MAX_FLOAT_PRECISION 53) Test script: --------------- <?php printf("%1.178f\n",2.6101217871994098106841176437026190222804657032275866191034545821878892978389944908891584507415473126457072794437408447265625e-54); /* 2^-178 */?> Expected result: ---------------- All requested decimal places are printed. Actual result: -------------- Only 53 decimal places are printed. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53918&edit=1