Bug #46145 [Opn->Wfx]: printf() %e format should make 2 digit exponent

From: Date: Mon, 03 May 2021 12:51:12 +0000
Subject: Bug #46145 [Opn->Wfx]: printf() %e format should make 2 digit exponent
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233662@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=46145&edit=1 ID: 46145 Updated by: cmb@php.net Reported by: lbayuk at users dot sourceforge dot net Summary: printf() %e format should make 2 digit exponent -Status: Open +Status: Wont fix Type: Bug Package: Strings related Operating System: Linux PHP Version: 5.2.6 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: That change has been introduced with commit d3e97520d9b[1], and might not have been done deliberately. Given the long standing behavior, and that it is even documented[2], I don't think that we should change that again. If anybody feels that there should be two digits at minimum, please pursue the RFC process[3]. [1] <https://github.com/php/php-src/commit/d3e97520d9b7806323c4f56c0ef69103297a28c7> [2] <https://www.php.net/manual/en/function.sprintf.php> [3] <https://wiki.php.net/rfc/howto> Is this still an issue with any of the actively supported PHP versions[1]? [1] <https://www.php.net/supported-versions.php> Previous Comments: ------------------------------------------------------------------------ [2019-10-18 12:04:09] girgias@php.net Seems this behaviour is the same since at least PHP 4.3: https://3v4l.org/IYt8e ------------------------------------------------------------------------ [2015-06-22 21:52:57] lbayuk at users dot sourceforge dot net (Verified still there in PHP-5.6.10 and fix email) ------------------------------------------------------------------------ [2008-09-29 01:07:30] lbayuk at pobox dot com After taking a look at your patch, approximately: /* * Make sure the exponent has at least 2 digits */ + if (t_len <= 1) { + *s++ = '0'; + } while (t_len--) { I got curious, since the code you added is described by the existing comment. So I checked back through CVS and sure enough similar code was there a while ago and was removed. It was: if (t_len == 1) *s++ = '0'; So it looks like the 2-digit minimum exponent code was *removed*. Certainly we would not want to put the code back in until we determine why it came out... perhaps there was a good reason. I haven't yet located the exact file version where the change was made. ------------------------------------------------------------------------ [2008-09-28 23:07:03] ilia dot cheishvili at gmail dot com 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 ------------------------------------------------------------------------ [2008-09-21 19:44:25] lbayuk at users dot sourceforge dot net 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 https://bugs.php.net/bug.php?id=46145&edit=1

« previous php.bugs (#233662) next »