|
template<typename T > |
T | constantE () |
| Constant \(e\). More...
|
|
template<typename T > |
T | constantLog2e () |
| Constant \(log2(e)\). More...
|
|
template<typename T > |
T | constantLog10e () |
| Constant \(log10(e)\). More...
|
|
template<typename T > |
T | constantLn2 () |
| Constant \(ln(2)\). More...
|
|
template<typename T > |
T | constantLn10 () |
| Constant \(ln(10)\). More...
|
|
template<typename T > |
T | constantPi () |
| Constant \(\pi\). More...
|
|
template<typename T > |
T | constantPiBy2 () |
| Constant \(\pi / 2\). More...
|
|
template<typename T > |
T | constantPiBy4 () |
| Constant \(\pi / 4\). More...
|
|
template<typename T > |
T | constant1ByPi () |
| Constant \(1 / \pi\). More...
|
|
template<typename T > |
T | constant2ByPi () |
| Constant \(2 / \pi\). More...
|
|
template<typename T > |
T | constant2BySqrtPi () |
| Constant \(2 / \sqrt{\pi}\). More...
|
|
template<typename T > |
T | constantSqrt2 () |
| Constant \(\sqrt{2}\). More...
|
|
template<typename T > |
T | constant1BySqrt2 () |
| Constant \(1 / \sqrt{2}\). More...
|
|
template<typename T > |
T | constantMaxIncrementable () |
| Maximal value that can be incremented to give a different value. More...
|
|
template<typename T > |
T | constantMinDecrementable () |
| Minimal value that can be decremented to give a different value. More...
|
|
template<typename T > |
bool | sameSign (T x, T y) |
| Tells whether x and y are of the same sign. More...
|
|
template<typename T > |
T | clamp (T value, T minVal, T maxVal) |
| Clamps a value to a range. More...
|
|
template<typename T > |
T | roundX (T number, size_t digits) |
| Rounds a number to the specified number of fractional digits. More...
|
|
template<typename T > |
T | round2 (T number) |
| Rounds a number to 2 fractional digits. More...
|
|
template<typename T > |
T | factorial (T n) |
| Returns the factorial of a given number. More...
|
|
template<typename VALUES_TYPE , typename INCREASE_TYPE = VALUES_TYPE> |
INCREASE_TYPE | proportionalIncrease (VALUES_TYPE initialValue, VALUES_TYPE finalValue) |
| Returns the proportional increase from an initial value to a final value. More...
|
|
template<typename T > |
T | increaseRate (T overallIncrease, size_t numPeriods) |
| Converts an proportional increase over a number of periods to an increase rate per period. More...
|
|
template<typename VALUES_TYPE , typename INCREASE_TYPE = VALUES_TYPE> |
INCREASE_TYPE | increaseRate (VALUES_TYPE initialValue, VALUES_TYPE finalValue, size_t numPeriods) |
| Returns the increase rate per period giving a final value from an initial value over a given number of periods. More...
|
|
Set of helper constants and functions.
template<typename VALUES_TYPE , typename INCREASE_TYPE = VALUES_TYPE>
INCREASE_TYPE shlublu::Math::proportionalIncrease |
( |
VALUES_TYPE |
initialValue, |
|
|
VALUES_TYPE |
finalValue |
|
) |
| |
|
inline |
Returns the proportional increase from an initial value to a final value.
The increase I
is defined as \(Vfinal = Vinitial + (Vinitial \times I)\), leading to \(I = (Vfinal / Vinitial) - 1\).
If I
be negative, this is a decrease.
- Template Parameters
-
VALUES_TYPE | the type of the initial and final values. This type should be arithmetic. |
INCREASE_TYPE | the type of the resulting increase. This type should be floating point. |
- Parameters
-
initialValue | the initial value |
finalValue | the final value |
- Returns
- The proportional increase \((Vfinal / Vinitial) - 1\).
initialValue
is converted to INCREASE_TYPE
to ensure this is a floating point division.
- Exceptions
-
std::invalid_argument | if initialValue is zero |
template<typename T >
T shlublu::Math::increaseRate |
( |
T |
overallIncrease, |
|
|
size_t |
numPeriods |
|
) |
| |
|
inline |
Converts an proportional increase over a number of periods to an increase rate per period.
This is the increase rate that produces the overall increase when applied to each period.
This rate R
is defined as \((R + 1) ^ N = O + 1\), where N
is the number of periods and O
the overall increase. This leads to \(R = \sqrt[N]{O + 1} - 1\).
This function only applies to \(O > -1\) as -1
or less would correspond to a decrease of 100% or more, leading the result R
not to be a real number.
- Template Parameters
-
T | the type of the overall increase and the returned rate. This type should be floating point. |
- Parameters
-
overallIncrease | the proportional increase over all the periods of times |
numPeriods | the number of periods of time that are covered |
- Returns
- the increase rate \(\sqrt[N]{O + 1} - 1\)
- Exceptions
-
std::invalid_argument | if numPeriods is zero |
std::domain_error | if overallIncrease <= -1 |
template<typename VALUES_TYPE , typename INCREASE_TYPE = VALUES_TYPE>
INCREASE_TYPE shlublu::Math::increaseRate |
( |
VALUES_TYPE |
initialValue, |
|
|
VALUES_TYPE |
finalValue, |
|
|
size_t |
numPeriods |
|
) |
| |
|
inline |
Returns the increase rate per period giving a final value from an initial value over a given number of periods.
This rate R
is defined as \(Vfinal = Vinitial \times (R + 1)^N\) where N
is the number of periods. This leads to \(R = \sqrt[N]{Vfinal / Vinitial} - 1\).
This function only applies to:
-
\(Vinitial > 0\) and
-
\(Vfinal / Vinitial > 0\) as zero or less would correspond to a decrease of 100% or more, leading the result
R
not to be a real number.
- Template Parameters
-
VALUES_TYPE | the type of the initial and final values. This type should be arithmetic. |
INCREASE_TYPE | the type of the resulting increase. This type should be floating point. |
- Parameters
-
initialValue | the initial value |
finalValue | the final value |
numPeriods | the number of periods of time that are covered |
- Returns
- the increase rate \(\sqrt[N]{Vfinal / Vinitial} - 1\)
- Exceptions
-
std::invalid_argument | if initialValue is zero or if numPeriods is zero |
std::domain_error | if initialValue is zero, or if finalValue / initialValue <= 0 |