#46145 [Com]: printf %e format should make 2 digit exponent
| From: | ilia dot cheishvili at gmail dot com | Date: | Sun, 28 Sep 2008 23:07:03 +0000 |
| Subject: | #46145 [Com]: printf %e format should make 2 digit exponent | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-129312@lists.php.net to get a copy of this message | ||
ID: 46145
Comment by: ilia dot cheishvili at gmail dot com
Reported By: lbayuk at pobox dot com
Status: Open
Bug Type: Strings related
Operating System: Linux
PHP Version: 5.2.6
New Comment:
The patch to fix this is here, along with all of the unit tests that
had to be modified to take the new, correct behavior into account:
http://pastebin.com/f641cf6fd
Previous Comments:
------------------------------------------------------------------------
[2008-09-21 19:44:25] lbayuk at pobox dot com
Description:
------------
PHP printf, sprintf, and fprintf with %e scientific notation produce a
1 digit exponent for values less than 1e10. Other implementation of
functions by the same name produce a minimum of 2 digits in the
exponent, as the C standard requires. Although it can be argued that PHP
is not bound by other standards, the following comment in
main/snprintf.c function php_conv_fp() [line 545] leads one to believe
this is a PHP bug:
/*
* Make sure the exponent has at least 2 digits
*/
Reproduce code:
---------------
<?php
printf("%8.2e\n", 1000000);
Expected result:
----------------
1.00e+06
Actual result:
--------------
<space>1.00e+6
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46145&edit=1