Update math.js to include min, max, and clamp functions#339
Draft
34638a wants to merge 2 commits intobigcommerce:masterfrom
Draft
Update math.js to include min, max, and clamp functions#33934638a wants to merge 2 commits intobigcommerce:masterfrom
34638a wants to merge 2 commits intobigcommerce:masterfrom
Conversation
Include of simple math helpers for inline calculations. All support Number types of Int and Float, but not edge case numbers such as NaN, +-infinity, or undefined. Min: given `A` and `B` return the smaller of the two on a standard number line. Max: given `A` and `B` return the larger of the two on a standard number line. Clamp: given `test`, `min` and `max` return the tested value if it falls within the range of `min` and `max` such that `min < test < max` is satisfied on a standard number line. If the constraint is not satisfied, return the closest bounding constraint.
Amendment - Typo,
Testing Protocol
```
{{log (min 1 5)}} {{! Resolved to 1}}
{{log (max 1 5)}} {{! Resolved to 5}}
{{log (clamp 6 1 5)}} {{! Resolved to 5}}
{{log (clamp -6 1 5)}} {{! Resolved to 1}}
{{log (clamp 3 1 5)}} {{! Resolved to 3}}
```
Contributor
Author
|
Amended initial proposal notes with updated comments, and a testing protocol. |
Contributor
Author
|
Drafting due to issues with PR semantics as per previously outlined instructions by BC devs. Will correct and re-file when time permits. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Include of simple math helpers for inline calculations. All support Number types of Int and Float, but not edge case numbers such as NaN, +-infinity, or undefined.
Min: given
AandBreturn the smaller of the two on a standard number line.Max: given
AandBreturn the larger of the two on a standard number line.Clamp: given
test,minandmaxreturn the tested value if it falls within the range ofminandmaxsuch thatmin < test < maxis satisfied on a standard number line. If the constraint is not satisfied, return the closest bounding constraint.Note for implementation
File:
thirdParty.jsin directoryhelpers/thirdParty.jswill also need line 71 to be modified to include the string names of the new functions.include: ['add', 'subtract', 'divide', 'multiply', 'floor', 'ceil', 'round', 'sum', 'avg', 'min', 'max', 'clamp']What? Why?
Because these math functions are currently missing from the standard library.
How was it tested?
None required, mirror of existing functionhelper.addwith math operations swapped for logical operations.Uses inline ternary operators for state evaluation.Edit:
Adding Of Testing Protocol in comment:
cc @bigcommerce/storefront-team