Skip to content

Commit a2dd77d

Browse files
committed
Add intadd function
1 parent d758f58 commit a2dd77d

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

ext/standard/basic_functions.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,9 @@ function is_nan(float $num): bool {}
30023002
/** @compile-time-eval */
30033003
function intdiv(int $num1, int $num2): int {}
30043004

3005+
/** @compile-time-eval */
3006+
function intadd(int $num1, int $num2): int {}
3007+
30053008
/** @compile-time-eval */
30063009
function is_infinite(float $num): bool {}
30073010

ext/standard/basic_functions_arginfo.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/math.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,3 +1215,17 @@ PHP_FUNCTION(intdiv)
12151215
RETURN_LONG(dividend / divisor);
12161216
}
12171217
/* }}} */
1218+
1219+
/* {{{ Returns sum of integers, allowing overflow */
1220+
PHP_FUNCTION(intadd)
1221+
{
1222+
zend_long addend1, addend2;
1223+
1224+
ZEND_PARSE_PARAMETERS_START(2, 2)
1225+
Z_PARAM_LONG(addend1)
1226+
Z_PARAM_LONG(addend2)
1227+
ZEND_PARSE_PARAMETERS_END();
1228+
1229+
RETURN_LONG(addend1 + addend2);
1230+
}
1231+
/* }}} */

ext/standard/tests/math/intadd.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
intadd functionality
3+
--FILE--
4+
<?php
5+
var_dump(intadd(41, 1) === 42);
6+
var_dump(intadd(-1, 1) === 0);
7+
var_dump(intadd(PHP_INT_MAX, 1) === PHP_INT_MIN);
8+
var_dump(intadd(PHP_INT_MIN, -1) === PHP_INT_MAX);
9+
?>
10+
--EXPECT--
11+
bool(true)
12+
bool(true)
13+
bool(true)
14+
bool(true)

0 commit comments

Comments
 (0)