Req #66959 [Ver]: bcadd with floats fails

From: Date: Thu, 07 Sep 2017 22:42:26 +0000
Subject: Req #66959 [Ver]: bcadd with floats fails
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211001@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66959&edit=1 ID: 66959 Updated by: cmb@php.net Reported by: james dot turner dot phpninja at gmail dot com Summary: bcadd with floats fails Status: Verified Type: Feature/Change Request Package: BC math related Operating System: Ubuntu 13 PHP Version: 5.5.10 Block user comment: N Private report: N New Comment: This issue is now documented at least.[1] Anyhow, I am not sure whether floats should explicitly supported as BCMath operands, since these are not arbitrary precision values, and it is unclear what their scale would be. Instead we may consider to introduce bcinit($number[, $scale]) which would use the given or default scale to return a respective string. Furthermore, bcinit() might be helpful if we ever consider to turn BCMath numbers into objects (what might result in quite considerable performance improvements, due to fewer necessary type conversions). [1] <http://svn.php.net/viewvc?view=revision&revision=343020> Previous Comments: ------------------------------------------------------------------------ [2016-07-13 23:55:47] cmb@php.net Related To: Bug #66745 ------------------------------------------------------------------------ [2016-07-13 23:46:40] cmb@php.net > Would be great if someone could make bcmath support scientific > notation... There would still be the issue that the string cast depends on the locale, e.g. <?php setlocale(LC_NUMERIC, 'de_DE.UTF-8'); // ... var_dump(bcadd(-0.05648055, -0.05648055, 8)); outputs string(10) "0.00000000" ------------------------------------------------------------------------ [2014-04-02 22:04:09] trainmaster at gmx dot net Some more examples (Output for 5.2.2 - 5.6.0alpha3): var_dump(bcadd(0,-0.00555555,9)); // string(12) "-0.005555550" var_dump((string) -0.00555555); // string(11) "-0.00555555" var_dump(bcadd(0,-0.00055555,9)); // string(12) "-0.000555550" var_dump((string) -0.00055555); // string(11) "-0.00055555" var_dump(bcadd(0,-0.00005555,9)); // string(11) "0.000000000" var_dump((string) -0.00005555); // string(10) "-5.555E-05" var_dump(bcadd(0,-0.00000555,9)); // string(11) "0.000000000" var_dump((string) -0.00000555); // string(9) "-5.55E-06" var_dump(bcadd(0,-0.00000055,9)); // string(11) "0.000000000" var_dump((string) -0.00000055); // string(8) "-5.5E-07" var_dump(bcadd(0,-0.00000005,9)); // string(11) "0.000000000" var_dump((string) -0.00000005); // string(6) "-5E-08" ------------------------------------------------------------------------ [2014-04-02 21:56:23] trainmaster at gmx dot net @nikic See bwoebi's example when string arguments are passed. The problem seems to be the scientific notation. ------------------------------------------------------------------------ [2014-04-01 13:47:04] nikic@php.net BCMath explicitly works with strings, not floating point numbers. In https://bugs.php.net/bug.php?id=55160 Mike made the decision that we should not have extra support for passing floats to bc functions. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=66959 -- Edit this bug report at https://bugs.php.net/bug.php?id=66959&edit=1

« previous php.bugs (#211001) next »