Skip to content

Commit ce0adad

Browse files
committed
init
1 parent d71eadc commit ce0adad

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ PHP NEWS
5151
. gmp_fact() reject values larger than unsigned long. (David Carlier)
5252
. gmp_pow/binomial/root/rootrem and shift/pow operators reject values
5353
larger than unsigned long. (David Carlier)
54+
. GMP exponentiation and shift operators now emit a deprecation warning
55+
when converting a float right operand to int loses precision. (Weilin Du)
5456

5557
- Hash:
5658
. Upgrade xxHash to 0.8.2. (timwolla)

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ PHP 8.6 UPGRADE NOTES
177177
is no longer maintained.
178178
RFC: https://wiki.php.net/rfc/eol-oniguruma
179179

180+
- GMP:
181+
. The shift (<<, >>) and exponentiation (**) operators on GMP objects now
182+
emit a deprecation warning when converting a float right operand to int
183+
loses precision.
184+
180185
========================================
181186
5. Changed Functions
182187
========================================

ext/gmp/gmp.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,15 @@ static zend_result shift_operator_helper(gmp_binary_ui_op_t op, zval *return_val
332332

333333
if (UNEXPECTED(Z_TYPE_P(op2) != IS_LONG)) {
334334
if (UNEXPECTED(!IS_GMP(op2))) {
335-
// For PHP 8.3 and up use zend_try_get_long()
336335
switch (Z_TYPE_P(op2)) {
337-
case IS_DOUBLE:
338-
shift = zval_get_long(op2);
339-
if (UNEXPECTED(EG(exception))) {
336+
case IS_DOUBLE: {
337+
bool failed;
338+
shift = zval_try_get_long(op2, &failed);
339+
if (UNEXPECTED(failed)) {
340340
return FAILURE;
341341
}
342342
break;
343+
}
343344
case IS_STRING:
344345
if (is_numeric_str_function(Z_STR_P(op2), &shift, NULL) != IS_LONG) {
345346
goto valueof_op_failure;

ext/gmp/tests/overloading_with_float_fractional.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ object(GMP)#2 (1) {
100100
["num"]=>
101101
string(1) "0"
102102
}
103+
104+
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
103105
object(GMP)#2 (1) {
104106
["num"]=>
105107
string(69) "150130937545296572356771972164254457814047970568738777235893533016064"
@@ -122,10 +124,14 @@ object(GMP)#2 (1) {
122124
["num"]=>
123125
string(1) "0"
124126
}
127+
128+
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
125129
object(GMP)#2 (1) {
126130
["num"]=>
127131
string(15) "184717953466368"
128132
}
133+
134+
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
129135
object(GMP)#2 (1) {
130136
["num"]=>
131137
string(1) "0"

0 commit comments

Comments
 (0)