-
Notifications
You must be signed in to change notification settings - Fork 7.9k
BcMath\Number methods are not 1-to-1 with bcmath functions due to int argument signature #18674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What I find interesting here is the difference in behavior. |
Here's the result on 3v4l: https://3v4l.org/Bi5Kl#v8.4.7 |
It makes sense why this happens: |
The RFC clearly states that the constructor accepts an int.
https://wiki.php.net/rfc/support_object_type_in_bcmath So this is not a bug. If you wish to discuss this issue in more detail, I recommend gathering opinions via the internal mailing list. Edit: In any case, discussion on the mailing list is necessary. |
Closing per previous comment |
I think that would be acceptable. I guess I'll have to sign up for the mailing list instead of just passively watching externals.io 😶🌫️ (mostly written before seeing the edit above) I agree this isn't technically a bug in the strictest sense, however it massively limits the utility or fit for purpose Number has given it will do the exact opposite of half the reason why someone would want to use it: preserve decimal places in arithmetic. Knowing that Thanks! |
Description
The following code:
Resulted in this output:
But I expected this output instead:
The signature of bcsub only accepts string which means integers and floats will both be cast to string, while
BcMath\Number::sub
allows integers, causing it to truncate the float and emit a deprecation notice instead of preserving the decimal places.Ultimately this means usages of bcmath functions cannot be automatically converted to objects and developers manually typing static math operations must enclose them in strings to avoid getting erroneous results.
PHP Version
Operating System
No response
The text was updated successfully, but these errors were encountered: