Skip to content

Commit 2ea1db9

Browse files
authored
Make max optional in clamp()
1 parent 600439b commit 2ea1db9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ext/standard/math.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,15 @@ PHP_FUNCTION(clamp)
410410
RETURN_THROWS();
411411
}
412412

413-
if (zend_compare(zmin, zmax) > 0) {
414-
zend_argument_value_error(2, "must be smaller than or equal to argument #3 ($max)");
415-
RETURN_THROWS();
416-
}
413+
if (zmax != NULL) {
414+
if (zend_compare(zmin, zmax) > 0) {
415+
zend_argument_value_error(2, "must be smaller than or equal to argument #3 ($max)");
416+
RETURN_THROWS();
417+
}
417418

418-
if (zend_compare(zmax, zvalue) == -1) {
419-
RETURN_COPY(zmax);
419+
if (zend_compare(zmax, zvalue) == -1) {
420+
RETURN_COPY(zmax);
421+
}
420422
}
421423

422424
if (zend_compare(zvalue, zmin) == -1) {

0 commit comments

Comments
 (0)