Coder-Spirit / php-bignumbers

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

Bug with the innerRound method with negative Decimal #30

Closed codisart closed 9 years ago

codisart commented 9 years ago

I was testing negative values for tangent and cotangente when i found several rounding errors.

I followed the process and I think there is a mistake with the rounding of negative numbers.

Exemple : I use the division of 0.984376 by -0.176077. the result is -5.59059956723478932512..

but with the Decimal::div(), it gives for the scale of 3 : -5.589 for the scale of 4 : -5.5904 for the scale of 5 : -5.59058 for the scale of 6 : -5.590598

I think i have pinpointed the probleme in Decimal::innerRound(). When a number is negative and if the next digit after the scale is greater than 5, the one should be substracted and not added.

castarco commented 9 years ago

Solved by @punkka with the pull request #31 .