Skip to content

Commit 1940580

Browse files
committed
Count bits instead of bytes
1 parent f1a4b2b commit 1940580

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ext/gmp/gmp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,11 +1350,11 @@ ZEND_FUNCTION(gmp_pow)
13501350
RETURN_THROWS();
13511351
}
13521352

1353-
double powmax = 2000;
1353+
double max_bits = 16000; // TODO: value is very small, but passed current test suite
13541354

13551355
if (Z_TYPE_P(base_arg) == IS_LONG && Z_LVAL_P(base_arg) >= 0) {
13561356
INIT_GMP_RETVAL(gmpnum_result);
1357-
if ((log(Z_LVAL_P(base_arg)) / log(256) * exp) > powmax) {
1357+
if ((log2(Z_LVAL_P(base_arg)) * exp) > max_bits) {
13581358
zend_value_error("base and exponent overflow");
13591359
RETURN_THROWS();
13601360
}
@@ -1363,7 +1363,7 @@ ZEND_FUNCTION(gmp_pow)
13631363
mpz_ptr gmpnum_base;
13641364
FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base, 1);
13651365
INIT_GMP_RETVAL(gmpnum_result);
1366-
if ((mpz_sizeinbase(gmpnum_base, 16) / 2.0 * exp) > powmax) {
1366+
if ((mpz_sizeinbase(gmpnum_base, 2) * exp) > max_bits) {
13671367
FREE_GMP_TEMP(temp_base);
13681368
zend_value_error("base and exponent overflow");
13691369
RETURN_THROWS();

0 commit comments

Comments
 (0)