helix.basic
Module provides basic numeric routines that are oftenly used in other
modules or helpful in projects that use helix.
Authors:
Victor Nakoryakov, nail-mail[at]mail.ru
- bit
equal
(real x, real y, int relprec = 16, int absprec = 16);
- Approximate equality function. In fact it's just a copy of phobos'es feqrel function,
but with modifcation that make it suitable for comparison of almost zero numbers.
However the cost of such possibility is little calculation overhead.
Params:
int relprec |
Minimal number of mantissa bits that have to be equal in x and y
to suppose their's equality. Makes sense in comparisons of values
enough far from zero. |
int absprec |
If absolute difference between x and y is less than 2^(-absprec)
they supposed to be equal. Makes sense in comparisons of values
enough near to zero. |
Returns:
true if x and y are supposed to be equal, false otherwise.
- real
lerp
(real a, real b, real t);
- Linear interpolation function.
Returns:
Value interpolated from a to b by value of t. If t is not within range [0; 1]
linear extrapolation is applied.
- template
MinMax
(T)
- Contains min and max functions for generic types that provide
opCmp.
- T
max
(T a, T b);
- Returns:
Maximal of a and b.
- T
min
(T a, T b);
- Returns:
Minimal of a and b.
- template
Clamp
(T)
- Contains clamping functions for generic types to which min and max
functions can be applied.
- T
clampBelow
(inout T x, T inf);
- Makes value of x to be not less than inf. Method can change value of x.
Returns:
Copy of x after clamping is applied.
- T
clampAbove
(inout T x, T sup);
- Makes value of x to be not greater than sup. Method can change value of x.
Returns:
Copy of x after clamping is applied.
- T
clamp
(inout T x, T inf, T sup);
- Makes value of x to be nor less than inf nor greater than sup.
Method can change value of x.
Returns:
Copy of x after clamping is applied.
- template
SimpleSwap
(T)
- Contains swap function for generic types.
- void
swap
(inout T a, inout T b);
- Swaps values of a and b.
|