-
Notifications
You must be signed in to change notification settings - Fork 7.8k
array_sum() with GMP can loose precision (LLP64) #16890
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
Labels
Comments
Oops. In the meantime I've noticed that |
cmb69
added a commit
to cmb69/php-src
that referenced
this issue
Nov 21, 2024
We must use `mpz_fits_si_p()` instead of `mpz_fits_slong_p()` since the latter is not suitable for LLP64 data models.
cmb69
added a commit
that referenced
this issue
Nov 25, 2024
* PHP-8.3: Fix GH-16890: array_sum() with GMP can loose precision (LLP64)
cmb69
added a commit
that referenced
this issue
Nov 25, 2024
* PHP-8.4: Fix GH-16890: array_sum() with GMP can loose precision (LLP64)
charmitro
pushed a commit
to wasix-org/php
that referenced
this issue
Mar 13, 2025
We must use `mpz_fits_si_p()` instead of `mpz_fits_slong_p()` since the latter is not suitable for LLP64 data models. libgmp, however, does not define `mpz_fits_si_p()` (which is an mpir addition), so we use `mpz_fits_slong_p()` there which should be fine. Closes phpGH-16891.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The following code:
Resulted in this output:
But I expected this output instead:
This is caused by an erroneous assumption in
gmp_cast_object()
for_IS_NUMBER
casts (as such it can affect other functions as well), namely thatZEND_LONG
would be asigned long
, but that is not true for LLP64 data models where it issigned long long
. On such platforms, values outside of range[INT_MIN, INT_MAX
] are converted to float.PHP Version
PHP-8.2
Operating System
Windows 64bit
The text was updated successfully, but these errors were encountered: