Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3002,6 +3002,9 @@ function is_nan(float $num): bool {}
/** @compile-time-eval */
function intdiv(int $num1, int $num2): int {}

/** @compile-time-eval */
function intadd(int $num1, int $num2): int {}

/** @compile-time-eval */
function is_infinite(float $num): bool {}

Expand Down
6 changes: 5 additions & 1 deletion ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions ext/standard/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,3 +1215,17 @@ PHP_FUNCTION(intdiv)
RETURN_LONG(dividend / divisor);
}
/* }}} */

/* {{{ Returns sum of integers, allowing overflow */
PHP_FUNCTION(intadd)
{
zend_long addend1, addend2;

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_LONG(addend1)
Z_PARAM_LONG(addend2)
ZEND_PARSE_PARAMETERS_END();

RETURN_LONG(addend1 + addend2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed integer overflow is undefined, this should be converted to unsigned (and back).

}
/* }}} */
14 changes: 14 additions & 0 deletions ext/standard/tests/math/intadd.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
intadd functionality
--FILE--
<?php
var_dump(intadd(41, 1) === 42);
var_dump(intadd(-1, 1) === 0);
var_dump(intadd(PHP_INT_MAX, 1) === PHP_INT_MIN);
var_dump(intadd(PHP_INT_MIN, -1) === PHP_INT_MAX);
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)