Coder-Spirit / php-bignumbers

A robust library to handle immutable big numbers inside PHP applications
MIT License
131 stars 29 forks source link

Division by zero warning in innerLog10 #60

Closed precariouspanther closed 7 years ago

precariouspanther commented 7 years ago

Two previous tickets have resolved other division by zero issues in the innerLog10 method, however we've encountered another when dealing with Decimals created from floats when the precision is being calculated to a higher value than the 'length'. This results in a negative $value_log10_approx which triggers a division by zero warning in \bcdiv:

image

To replicate:

$x = Decimal::fromFloat(1.001);
// PHP Warning:  bcdiv(): Division by zero in /vendor/litipk/php-bignumbers/src/Decimal.php on line 1159
$x->div(Decimal::fromFloat(1.0));