Std.Math
34 public declarations
- abs
T -> T where T: Ord + Zero + SubThe distance of a value from zero.
- between
T -> T -> T -> Bool where T: OrdWhether a value lies between two bounds, inclusive at both ends.
- binaryGcd
Int -> Int -> IntStein's binary algorithm for the greatest common divisor.
- branchlessAbs
Int -> IntBranchless absolute value of an integer.
- branchlessMax
Int -> Int -> IntBranchless maximum of two integers.
- branchlessMin
Int -> Int -> IntBranchless minimum of two integers.
- checkedPow
T -> Int -> Option[T] where T: One + MulA value raised to a power, or `None` when the exponent is negative.
- clamp
T -> T -> T -> T where T: OrdConfine a value to a range, inclusive at both ends.
- cube
T -> T where T: MulA value cubed.
- digitCount
T -> Int where T: Ord + Zero + One + Add + Sub + DivThe number of decimal digits, counting a lone nought as one and ignoring a
- divide
T -> T -> Option[T] where T: DivTruncating division, or `None` when the divisor is nought.
- divides
T -> T -> Bool where T: Rem + Zero + OrdWhether a value divides another with no remainder. Nought divides nothing.
- divMod
T -> T -> Option[(T, T)] where T: Div + RemThe quotient and the remainder together, or `None` for a nought divisor.
- factorial
T -> T where T: Ord + Zero + One + Add + MulThe product of every whole number from one up to the value.
- gcd
T -> T -> T where T: Ord + Zero + One + Add + Sub + RemThe greatest common divisor, by Euclid's algorithm.
- ilog2
Int -> Option[Int]Fast integer base-2 logarithm (floor(log2(n))) using bit shifts.
- isEven
T -> Bool where T: Rem + Zero + One + Add + OrdWhether a value is even.
- isOdd
T -> Bool where T: Rem + Zero + One + Add + OrdWhether a value is odd.
- isPowerOfTwo
Int -> BoolTests whether an integer is an exact positive power of two (1, 2, 4, 8, ...).
- isPrime
T -> Bool where T: Ord + Zero + One + Add + Mul + RemWhether a value is prime. Values below two are not.
- isqrt
T -> Option[T] where T: Ord + Zero + One + Add + DivThe greatest value whose square does not exceed the given one.
- lcm
T -> T -> T where T: Ord + Zero + One + Add + Sub + Mul + Div + RemThe least common multiple. Nought with either argument nought, since no
- max
T -> T -> T where T: OrdThe larger of two values.
- maxBy
T -> T -> fn(T, T) -> Bool -> TThe larger of two values, chosen by a comparison the caller supplies.
- min
T -> T -> T where T: OrdThe smaller of two values.
- minBy
T -> T -> fn(T, T) -> Bool -> TThe smaller of two values, chosen by a comparison the caller supplies.
- nextPowerOfTwo
Int -> IntComputes the smallest power of two greater than or equal to n.
- pow
T -> Int -> T where T: One + MulA value raised to a non-negative power, by repeated squaring.
- pred
T -> T where T: One + SubThe previous value.
- remainder
T -> T -> Option[T] where T: RemThe remainder of a truncating division, or `None` for a nought divisor.
- signum
T -> T where T: Ord + Zero + One + SubThe sign of a value: -1, 0, or 1, in the value's own type.
- square
T -> T where T: MulA value squared.
- subtract
T -> T -> T where T: SubOne value taken from another, with the arguments in the order a reader meets
- succ
T -> T where T: One + AddThe next value.
