X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/5af99cb7def7f5a9b19db6a8e214920dd233113d..f1667ed7321c6802dc2e96532b0b96eabba4b929:/numeric.js?ds=sidebyside diff --git a/numeric.js b/numeric.js index 78ea64c..44c7cd5 100644 --- a/numeric.js +++ b/numeric.js @@ -618,6 +618,29 @@ export const { }; })(); +/** + * Returns the result of converting the provided number to an integer + * or infinity. + * + * ☡ This function does not allow big·int arguments. + */ +export const toIntegerOrInfinity = ($) => { + const integer = trunc($); + if (isNan(integer) || integer == 0) { + // The provided value truncs to nan or (positive or negative) zero. + return 0; + } else if (integer == POSITIVE_INFINITY) { + // The provided value truncs to positive infinity. + return POSITIVE_INFINITY; + } else if (integer == NEGATIVE_INFINITY) { + // The provided value truncs to negative infinity. + return NEGATIVE_INFINITY; + } else { + // The provided value truncs to an integer. + return integer; + } +}; + /** * Returns the result of converting the provided value to a number. *