Skip to content

Commit

Permalink
Unary minus const expression consistency
Browse files Browse the repository at this point in the history
- of 0.0 should result in -0.0

Closes GH-10978
  • Loading branch information
iluuu1994 committed Mar 31, 2023
1 parent 5e76c6d commit 41bbb11
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.1.19

- Core:
. Fix inconsistent float negation in constant expressions. (ilutov)

- DOM:
. Fixed bug #80602 (Segfault when using DOMChildNode::before()).
(Nathan Freeman)
Expand Down
16 changes: 16 additions & 0 deletions Zend/tests/unary_minus_const_expr_consistency.phpt
@@ -0,0 +1,16 @@
--TEST--
Unary minus constant expression consistency
--FILE--
<?php

const ZERO = 0.0;
const MINUS_ZERO = -ZERO;
$minus_zero = -ZERO;

var_dump(MINUS_ZERO);
var_dump($minus_zero);

?>
--EXPECT--
float(-0)
float(-0)
4 changes: 2 additions & 2 deletions Zend/zend_ast.c
Expand Up @@ -662,8 +662,8 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast
if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[0], scope) != SUCCESS)) {
ret = FAILURE;
} else {
ZVAL_LONG(&op1, 0);
ret = sub_function(result, &op1, &op2);
ZVAL_LONG(&op1, -1);
ret = mul_function(result, &op1, &op2);
zval_ptr_dtor_nogc(&op2);
}
break;
Expand Down

0 comments on commit 41bbb11

Please sign in to comment.