Bug #66959 [NEW]: bcadd with floats fails
From: james dot turner dot phpninja at gmail dot com
Operating system: Ubuntu 13
PHP version: 5.5.10
Package: *Math Functions
Bug Type: Bug
Bug description:bcadd with floats fails
Description:
------------
bcadd does not appear to work for certain numbers when using floats as
inputs rather than strings.
This is particularly apparent if you json_decode from json to php
variables where floats are generated as you get floats not strings. Any
attempt at casting to a string produces the same output.
I can only assume it's actually an issue with float->string casting.
Test script:
---------------
$a = -0.05648055;
$b = -0.00000545;
$c = bcadd($a,$b,9);
$d = $a+$b;
echo $c; // => -0.05648055 <- WRONG
echo $d; // => -0.056486 <- CORRECT
assert($c == -0.056486);
Expected result:
----------------
assert ok
Usage of string literals for the negative floats works fine. However
casting the floats to strings fails (which is why I assume that bcadd
also has the same problem in casting to strings before computation).
Actual result:
--------------
assert fail
--
Edit bug report at https://bugs.php.net/bug.php?id=66959&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66959&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66959&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66959&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66959&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66959&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66959&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66959&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66959&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66959&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66959&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66959&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66959&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66959&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66959&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66959&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66959&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66959&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66959&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66959&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66959&r=mysqlcfg
Thread (7 messages)
- james dot turner dot phpninja at gmail dot com