-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Add clamp function #7191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+154
−1
Closed
[RFC] Add clamp function #7191
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4d5c4fb
Add clamp function
thinkverse 7d6ae1f
Fix clamp error message
thinkverse 321afb1
Fix clamp return value
thinkverse 3d0a6e8
Add basic test for clamp function
thinkverse 4e2d3ae
Fix basic clamp test
thinkverse 5c80a09
Refactor clamp function basic tests
thinkverse fc5342d
Fix clamp basic test 1
thinkverse 4129f61
Merge branch 'master' into feat/math-clamp
thinkverse 279c073
Fix clamp function return type
thinkverse bc7aacb
Fix clamp function error message
thinkverse 873f323
Merge master
thinkverse 48195b3
Merge branch 'master' into feat/math-clamp
thinkverse f46f20f
Add clamp exception to test case
thinkverse 59e64cf
Refactor `clamp` to use zend_compare
thinkverse 1780dd1
Remove unnecessary return value check
thinkverse 9c887ec
Update clamp test suite
thinkverse 5359f34
Fix clamp test suite names
thinkverse 20a25bc
clamp now handles NAN values
thinkverse c16076b
Update clamp tests
thinkverse 696edac
Fix wording, NaN -> NAN
thinkverse 641e2f4
Fix clamp NAN behaviour
thinkverse bae3315
Fix clamp not returning NAN when passed to ``
thinkverse 1ae79ba
Switch from RETURN_COPY to RETURN_COPY_VALUE
thinkverse 388b2b5
Regenerate basic functions arginfo
thinkverse 8b5bb09
Revert "Regenerate basic functions arginfo"
thinkverse 1dca2f4
Merge branch 'master' into feat/math-clamp
thinkverse 1dad42f
Regenerate basic functions arginfo
thinkverse 2b46215
Merge branch 'master' into feat/math-clamp
thinkverse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--TEST-- | ||
Test clamp() function : basic functionality 01 | ||
--FILE-- | ||
<?php | ||
echo "*** Testing clamp() : basic functionality 01 ***\n"; | ||
|
||
var_dump(clamp(0, 1, 2)); | ||
var_dump(clamp(2, 1, 3)); | ||
var_dump(clamp(3, 1, 4)); | ||
var_dump(clamp(5, 1, 4)); | ||
var_dump(clamp(5, 1, 5)); | ||
var_dump(clamp(0.0, 1.0, 2.0)); | ||
var_dump(clamp(1.5, 1.0, 2.0)); | ||
var_dump(clamp(2.0, 1.0, 2.5)); | ||
var_dump(clamp(3.0, 1.0, 2.5)); | ||
var_dump(clamp(0, 3.0, 3.5)); | ||
|
||
try { | ||
var_dump(clamp(5, 5, 1)); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
var_dump(clamp(1, 3.5, 3.0)); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
var_dump(clamp(0, null, 3.5)); | ||
|
||
try { | ||
var_dump(clamp(5, 1, null)); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
?> | ||
--EXPECTF-- | ||
*** Testing clamp() : basic functionality 01 *** | ||
int(1) | ||
int(2) | ||
int(3) | ||
int(4) | ||
int(5) | ||
float(1) | ||
float(1.5) | ||
float(2) | ||
float(2.5) | ||
float(3) | ||
clamp(): Argument #2 ($min) cannot be greater than Argument #3 ($max) | ||
clamp(): Argument #2 ($min) cannot be greater than Argument #3 ($max) | ||
|
||
Deprecated: clamp(): Passing null to parameter #2 ($min) of type int|float is deprecated in %s on line %d | ||
int(0) | ||
|
||
Deprecated: clamp(): Passing null to parameter #3 ($max) of type int|float is deprecated in %s on line %d | ||
clamp(): Argument #2 ($min) cannot be greater than Argument #3 ($max) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--TEST-- | ||
Test clamp() function : basic functionality 02 | ||
--FILE-- | ||
<?php | ||
echo "*** Testing clamp() : basic functionality 02 ***\n"; | ||
|
||
var_dump(clamp(0, 0.0, 2)); | ||
var_dump(clamp(0.0, 0, 2)); | ||
try { | ||
var_dump(clamp(0.0, NAN, 2)); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
try { | ||
var_dump(clamp(INF, NAN, 2)); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
var_dump(clamp(0x10, 0x01, 2)); | ||
var_dump(clamp(10, "-2.345e1", 2.345e1)); | ||
var_dump(clamp(24.0, 027, 25)); | ||
var_dump(clamp(2.345e1, "-2.345e1", 2.345e1)); | ||
var_dump(clamp(0.0, null, 2)); | ||
var_dump(clamp(0.0, null, null)); | ||
var_dump(clamp(0.0, null, false)); | ||
try { | ||
var_dump(clamp(INF, false, NAN)); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
var_dump(clamp(NAN, 0, 2)); | ||
?> | ||
--EXPECTF-- | ||
*** Testing clamp() : basic functionality 02 *** | ||
float(0) | ||
int(0) | ||
clamp(): Argument #2 ($min) cannot be of type NAN | ||
clamp(): Argument #2 ($min) cannot be of type NAN | ||
int(2) | ||
int(10) | ||
float(24) | ||
float(23.45) | ||
|
||
Deprecated: clamp(): Passing null to parameter #2 ($min) of type int|float is deprecated in %s on line %d | ||
int(0) | ||
|
||
Deprecated: clamp(): Passing null to parameter #2 ($min) of type int|float is deprecated in %s on line %d | ||
|
||
Deprecated: clamp(): Passing null to parameter #3 ($max) of type int|float is deprecated in %s on line %d | ||
int(0) | ||
|
||
Deprecated: clamp(): Passing null to parameter #2 ($min) of type int|float is deprecated in %s on line %d | ||
int(0) | ||
clamp(): Argument #3 ($max) cannot be of type NAN | ||
float(NAN) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.