Skip to content

Commit bae3315

Browse files
committed
Fix clamp not returning NAN when passed to ``
1 parent 641e2f4 commit bae3315

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

ext/standard/math.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ PHP_FUNCTION(clamp)
246246

247247
if (zend_compare(zmax, zvalue) == -1) {
248248
RETURN_COPY(zmax);
249-
} else if (zend_compare(zmin, zvalue) == -1) {
250-
RETURN_COPY(zvalue);
251-
} else {
249+
} else if (zend_compare(zvalue, zmin) == -1) {
252250
RETURN_COPY(zmin);
251+
} else {
252+
RETURN_COPY(zvalue);
253253
}
254254
}
255255
/* }}} */

ext/standard/tests/math/clamp_basic2.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ var_dump(clamp(NAN, 0, 2));
3232
?>
3333
--EXPECTF--
3434
*** Testing clamp() : basic functionality 02 ***
35-
float(0)
3635
int(0)
36+
float(0)
3737
clamp(): Argument #2 ($min) must be smaller than or equal to argument #3 ($max)
3838
clamp(): Argument #2 ($min) must be smaller than or equal to argument #3 ($max)
3939
int(2)
@@ -42,14 +42,14 @@ float(24)
4242
float(23.45)
4343

4444
Deprecated: clamp(): Passing null to parameter #2 ($min) of type int|float is deprecated in %s on line %d
45-
int(0)
45+
float(0)
4646

4747
Deprecated: clamp(): Passing null to parameter #2 ($min) of type int|float is deprecated in %s on line %d
4848

4949
Deprecated: clamp(): Passing null to parameter #3 ($max) of type int|float is deprecated in %s on line %d
50-
int(0)
50+
float(0)
5151

5252
Deprecated: clamp(): Passing null to parameter #2 ($min) of type int|float is deprecated in %s on line %d
53-
int(0)
53+
float(0)
5454
clamp(): Argument #2 ($min) must be smaller than or equal to argument #3 ($max)
55-
int(0)
55+
float(NAN)

0 commit comments

Comments
 (0)