From:             
Operating system: Windows (32-bit system)
PHP version:      5.3.5
Package:          Math related
Bug Type:         Bug
Bug description:printf of floating point variable prints maximum of 53 decimal 
places

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 bug report at http://bugs.php.net/bug.php?id=53918&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=53918&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=53918&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=53918&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=53918&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=53918&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=53918&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=53918&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=53918&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=53918&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=53918&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=53918&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=53918&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=53918&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=53918&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53918&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53918&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=53918&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=53918&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=53918&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=53918&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=53918&r=mysqlcfg

Reply via email to