Numeric Module
Generic numeric helpers: clamping, linear interpolation, and inclusive-range checks.
Built on F#'s built-in arithmetic/comparison constraints, so they work for
Functions and values
| Function or value |
Description
|
Full Usage:
Numeric.clamp lo hi value
Parameters:
'a
-
Inclusive lower bound.
hi : 'a
-
Inclusive upper bound.
value : 'a
-
Value to clamp.
Returns: 'a
Modifiers: inline Type parameters: 'a |
Restricts value to the inclusive range [lo, hi]. Total: never throws. If lo is greater than hi the two comparisons below still run in order, so the result is always exactly lo or hi (never a value strictly between them, and never the unclamped value): anything less than lo clamps to lo, everything else clamps to hi.
Example
|
Full Usage:
Numeric.inverseLerp a b value
Parameters:
^a
-
Value at t = 0.
b : ^a
-
Value at t = 1.
value : ^a
-
Value to locate between a and b.
Returns: ^a
Modifiers: inline Type parameters: ^a, ^a |
Inverse of lerp: finds the fraction
Total for floating-point types: when a equals b the divisor is
zero and the result is
Example
|
Full Usage:
Numeric.isBetween lo hi value
Parameters:
'a
-
Inclusive lower bound.
hi : 'a
-
Inclusive upper bound.
value : 'a
-
Value to test.
Returns: bool
Modifiers: inline Type parameters: 'a |
Returns
If lo is greater than hi the range is empty, so this always returns
Example
|
Full Usage:
Numeric.lerp a b t
Parameters:
^a
-
Value at t = 0.
b : ^a
-
Value at t = 1.
t : ^a
-
Interpolation fraction.
Returns: ^a
Modifiers: inline Type parameters: ^a, ^a, ^b |
Linearly interpolates between a and b by fraction t.
Unclamped: t is not restricted to [0, 1].
Example
|
Full Usage:
Numeric.one
Returns: ^a
Modifiers: inline Type parameters: ^a |
The multiplicative identity for numeric type
Example
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float |
Full Usage:
Numeric.zero
Returns: ^a
Modifiers: inline Type parameters: ^a |
The additive identity for numeric type
Example
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float |
TDesu.FSharp