Edit report at http://bugs.php.net/bug.php?id=53918&edit=1
ID: 53918 Updated by: il...@php.net Reported by: exploringbinary at gmail dot com Summary: printf of floating point variable prints maximum of 53 decimal places -Status: Open +Status: Bogus 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: 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/ Previous Comments: ------------------------------------------------------------------------ [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