Skip to content

Commit 3450a45

Browse files
authored
Make max optional in clamp()
1 parent 2ea1db9 commit 3450a45

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
@@ -447,13 +447,15 @@ ZEND_FRAMELESS_FUNCTION(clamp, 3)
447447
RETURN_THROWS();
448448
}
449449

450-
if (zend_compare(zmin, zmax) > 0) {
451-
zend_argument_value_error(2, "must be smaller than or equal to argument #3 ($max)");
452-
RETURN_THROWS();
453-
}
450+
if (zmax != NULL) {
451+
if (zend_compare(zmin, zmax) > 0) {
452+
zend_argument_value_error(2, "must be smaller than or equal to argument #3 ($max)");
453+
RETURN_THROWS();
454+
}
454455

455-
if (zend_compare(zmax, zvalue) == -1) {
456-
RETURN_COPY(zmax);
456+
if (zend_compare(zmax, zvalue) == -1) {
457+
RETURN_COPY(zmax);
458+
}
457459
}
458460

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

0 commit comments

Comments
 (0)