php-src icon indicating copy to clipboard operation
php-src copied to clipboard

bcsub incorrect result when second operand precision is higher than the scale applied to the result

Open sgurdiel opened this issue 4 years ago • 3 comments

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

sgurdiel avatar Apr 01 '22 15:04 sgurdiel

damianwadley avatar Apr 01 '22 16:04 damianwadley

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.

github-actions[bot] avatar Apr 16 '22 00:04 github-actions[bot]

@damianwadley appreciate you getting back.

My bad for assuming truncation is applied to the operands before the mathematical operation.

sgurdiel avatar Apr 16 '22 12:04 sgurdiel