HMath.Basic¶
Module index · Numerical conventions
On this page¶
| API | Purpose |
|---|---|
| factorial | Return n! using unbounded Integer arithmetic; 0! is 1. |
| fibonacci | Return the zero-based Fibonacci number (F0=0, F1=1). |
| isPrime | Test an Integer by trial division through its square root. |
| clamp | Given lower bound, upper bound, then value, return max lower (min upper value). |
| lerp | Given endpoints a and b then parameter t, return a+(b-a)*t. |
Documentation
factorial
factorial :: Integer -> Integer Source #
Return n! using unbounded Integer arithmetic; 0! is 1. Negative n raises a pure error. For a checked Either result use HMath.Scalar.factorialChecked. Example: factorial 5 == 120.
fibonacci
fibonacci :: Integer -> Integer Source #
Return the zero-based Fibonacci number (F0=0, F1=1). Negative indices raise a pure error; use HMath.Scalar.fibonacciChecked for checked input. Example: fibonacci 10 == 55.
isPrime
isPrime :: Integer -> Bool Source #
Test an Integer by trial division through its square root. All n below 2 return False; 2 returns True. Example: isPrime 17 == True. This is a reference primality test for modest inputs.
clamp
clamp :: Ord a => a -> a -> a -> a Source #
Given lower bound, upper bound, then value, return max lower (min upper value). Bounds must be ordered by the caller; reversed bounds are not rejected. Example: clamp 0 1 2 == 1. Use clampChecked for validation.
lerp
lerp :: Fractional a => a -> a -> a -> a Source #
Given endpoints a and b then parameter t, return a+(b-a)*t. Values outside [0,1] extrapolate; arithmetic follows the chosen Fractional type without validation. Example: lerp 10 20 0.5 == 15.