Integer arithmetic utilities and number predicates, homed on the Num class.
Num(Num int? x)Test whether x is a machine INT – the base integer type. Floats, rationals, bigints, booleans, and nil are not (N5: counts and indexes are machine INTs).
Parameters:
ANY — Value to testReturns: BOOL — #t only for machine integers
Examples:
(list (Num int? 3) (Num int? ())) => (#t #f)(Num inc n)Add one to a number.
Parameters:
NUMBER — Number to incrementReturns: NUMBER — n + 1
(Num dec n)Subtract one from a number.
Parameters:
NUMBER — Number to decrementReturns: NUMBER — n - 1
(Num negate n)Return the negation of a number.
Parameters:
NUMBER — Number to negateReturns: NUMBER — The additive inverse of n
(Num abs n)Return the absolute value of a number.
Parameters:
NUMBER — NumberReturns: NUMBER — Absolute value of n
(Num min a . more)Return the smallest of one or more numbers.
Parameters:
NUMBER — First numberNUMBER — More numbersReturns: NUMBER — The smallest argument
Examples:
(Num min 3 1 2) => 1(Num max a . more)Return the largest of one or more numbers.
Parameters:
NUMBER — First numberNUMBER — More numbersReturns: NUMBER — The largest argument
Examples:
(Num max 3 1 2) => 3(Num quotient a b)Integer division truncating toward zero – always an integer, where / on integers may promote to a rational under the tower.
Parameters:
INT — DividendINT — DivisorReturns: INT — trunc(a/b)
Examples:
(Num quotient -7 2) => -3(Num remainder a b)Truncating remainder (the dividend’s sign) – the pair of quotient; identical to % on integers.
Parameters:
INT — DividendINT — DivisorReturns: INT — a - b*trunc(a/b)
Examples:
(Num remainder -7 2) => -1(Num modulo a b)Floored modulo: the result takes the DIVISOR’s sign – (Num modulo -7 3) is 2 where % gives -1.
Parameters:
INT — DividendINT — DivisorReturns: INT — a - b*floor(a/b)
Examples:
(Num modulo -7 3) => 2(Num divmod a b)Truncating quotient and remainder together.
Parameters:
INT — DividendINT — DivisorReturns: LIST — (quotient remainder)
Examples:
(Num divmod 7 2) => (3 1)(Num isqrt n)Integer square root: the largest k with k*k <= n (Newton’s method); errors on a negative input.
Parameters:
INT — Non-negative integerReturns: INT — floor(sqrt(n))
Examples:
(Num isqrt 99) => 9(Num clamp lo hi n)Clamp a number to the range [lo, hi].
Parameters:
NUMBER — Lower boundNUMBER — Upper boundNUMBER — Value to clampReturns: NUMBER — n clamped to [lo, hi]
Examples:
(Num clamp 0 10 15) => 10(Num min-by f a b)Return the value with the smaller result under f.
Parameters:
CALLABLE — Projection functionANY — First valueANY — Second valueReturns: ANY — The value whose projection is smaller
(Num max-by f a b)Return the value with the larger result under f.
Parameters:
CALLABLE — Projection functionANY — First valueANY — Second valueReturns: ANY — The value whose projection is larger
(Num zero? n)Test whether a number is zero.
Parameters:
NUMBER — Number to testReturns: BOOL — True if n is zero
(Num positive? n)Test whether a number is positive.
Parameters:
NUMBER — Number to testReturns: BOOL — True if n is positive
(Num negative? n)Test whether a number is negative.
Parameters:
NUMBER — Number to testReturns: BOOL — True if n is negative
(Num even? n)Test whether an integer is even.
Parameters:
NUMBER — Integer to testReturns: BOOL — True if n is even
(Num odd? n)Test whether an integer is odd.
Parameters:
NUMBER — Integer to testReturns: BOOL — True if n is odd
(Num gcd . args)Compute the greatest common divisor. Variadic: (Num gcd a b c …) folds pairwise.
Returns: NUMBER — Greatest common divisor of all arguments
(Num lcm . args)Compute the least common multiple. Variadic: (Num lcm a b c …) folds pairwise.
Returns: NUMBER — Least common multiple of all arguments
(Num expt base exp)Compute base raised to a non-negative integer exponent by repeated squaring; errors on a negative exponent.
Parameters:
NUMBER — BaseNUMBER — Non-negative integer exponentReturns: NUMBER — base raised to the power exp
Examples:
(Num expt 2 10) => 1024