-
Notifications
You must be signed in to change notification settings - Fork 2
feat(math): add clamp function #138
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
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #138 +/- ##
=======================================
Coverage ? 89.37%
=======================================
Files ? 43
Lines ? 2475
Branches ? 0
=======================================
Hits ? 2212
Misses ? 263
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
NirLevi-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NirLevi-starkware reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @noa-starkware)
packages/utils/src/math/utils.cairo line 440 at r1 (raw file):
assert_eq!(10_u64.clamp(0_u64, 20_u64), 10_u64, "clamp failed"); assert_eq!((-10_i64).clamp(0_i64, 20_i64), 0_i64, "clamp failed"); assert_eq!(30_i64.clamp(0_i64, 20_i64), 20_i64, "clamp failed");
add one that the min and the max are the same save.
f958550 to
fe1b84b
Compare
noa-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @NirLevi-starkware)
packages/utils/src/math/utils.cairo line 440 at r1 (raw file):
Previously, NirLevi-starkware (Nir Levi) wrote…
add one that the min and the max are the same save.
Done.
NirLevi-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NirLevi-starkware reviewed 1 of 1 files at r2, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @noa-starkware)
Note
Introduces a generic
Clamp<T>trait withclamp(min, max)plus unit tests, including panic on invalid bounds.packages/utils/src/math/utils.cairo)Clamp<T>trait withclamp(self, min, max) -> T.TwithPartialOrd,Copy; assertsmin <= maxand bounds value to[min, max].clamp_testcoveringu64,i64,u256, andclamp_test_panicverifying panic onmin > max.Written by Cursor Bugbot for commit 10f6baa. This will update automatically on new commits. Configure here.
This change is