php-src
php-src copied to clipboard
bcsub incorrect result when second operand precision is higher than the scale applied to the result
Description
The following code:
<?php
echo bcsub('4.102', '1', 2);
echo bcsub('4', '1.107', 2);
Resulted in this output:
3.10
2.89
But I expected this output instead:
3.10
2.90
Notes:
The behavior of this use case bcsub('4', '1.107', 2) should be aligned with the the rest of the functions in the extension
i.e. scale down the precision of the second operand without rounding before executing the subtraction operation.
PHP Version
PHP 8.0.17
Operating System
No response
- bc does not respect scale during subtraction operations
- As far as I know, where used, scale operates by truncation without no rounding, so when PHP "scales" the result of 2.893 (because bc doesn't) the output is 2.89
No feedback was provided. The issue is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so. Thank you.
@damianwadley appreciate you getting back.
My bad for assuming truncation is applied to the operands before the mathematical operation.