Basic functions¶
-
template<typename T>
constexpr T abs(const T x) noexcept¶ Compile-time absolute value function.
- Parameters
x – a real-valued input.
- Returns
the absolute value of
x
, \( |x| \).
-
template<typename T>
constexpr return_t<T> ceil(const T x) noexcept¶ Compile-time ceil function.
- Parameters
x – a real-valued input.
- Returns
computes the ceiling-value of the input.
-
template<typename T1, typename T2>
constexpr T1 copysign(const T1 x, const T2 y) noexcept¶ Compile-time copy sign function.
- Parameters
x – a real-valued input
y – a real-valued input
- Returns
replace the signbit of
x
with the signbit ofy
.
-
template<typename T>
constexpr return_t<T> exp(const T x) noexcept¶ Compile-time exponential function.
- Parameters
x – a real-valued input.
- Returns
\( \exp(x) \) using
\[ \exp(x) = \dfrac{1}{1-\dfrac{x}{1+x-\dfrac{\frac{1}{2}x}{1 + \frac{1}{2}x - \dfrac{\frac{1}{3}x}{1 + \frac{1}{3}x - \ddots}}}} \]The continued fraction argument is split into two parts: \( x = n + r \), where \( n \) is an integer and \( r \in [-0.5,0.5] \).
-
template<typename T>
constexpr return_t<T> expm1(const T x) noexcept¶ Compile-time exponential-minus-1 function.
- Parameters
x – a real-valued input.
- Returns
\( \exp(x) - 1 \) using
\[ \exp(x) = \sum_{k=0}^\infty \dfrac{x^k}{k!} \]
-
template<typename T>
constexpr T factorial(const T x) noexcept¶ Compile-time factorial function.
- Parameters
x – a real-valued input.
- Returns
Computes the factorial value \( x! \). When
x
is an integral type (int
,long int
, etc.), a simple recursion method is used, along with table values. Whenx
is real-valued,factorial(x) = tgamma(x+1)
.
-
template<typename T>
constexpr return_t<T> floor(const T x) noexcept¶ Compile-time floor function.
- Parameters
x – a real-valued input.
- Returns
computes the floor-value of the input.
-
template<typename T1, typename T2>
constexpr common_return_t<T1, T2> fmod(const T1 x, const T2 y) noexcept¶ Compile-time remainder of division function.
- Parameters
x – a real-valued input.
y – a real-valued input.
- Returns
computes the floating-point remainder of \( x / y \) (rounded towards zero) using
\[ \text{fmod}(x,y) = x - \text{trunc}(x/y) \times y \]
-
template<typename T1, typename T2>
constexpr common_return_t<T1, T2> hypot(const T1 x, const T2 y) noexcept¶ Compile-time Pythagorean addition function.
- Parameters
x – a real-valued input.
y – a real-valued input.
- Returns
Computes \( x \oplus y = \sqrt{x^2 + y^2} \).
-
template<typename T>
constexpr return_t<T> log(const T x) noexcept¶ Compile-time natural logarithm function.
- Parameters
x – a real-valued input.
- Returns
\( \log_e(x) \) using
\[ \log\left(\frac{1+x}{1-x}\right) = \dfrac{2x}{1-\dfrac{x^2}{3-\dfrac{4x^2}{5 - \dfrac{9x^3}{7 - \ddots}}}}, \ \ x \in [-1,1] \]The continued fraction argument is split into two parts: \( x = a \times 10^c \), where \( c \) is an integer.
-
template<typename T>
constexpr return_t<T> log1p(const T x) noexcept¶ Compile-time natural-logarithm-plus-1 function.
- Parameters
x – a real-valued input.
- Returns
\( \log_e(x+1) \) using
\[ \log(x+1) = \sum_{k=1}^\infty \dfrac{(-1)^{k-1}x^k}{k}, \ \ |x| < 1 \]
-
template<typename T>
constexpr return_t<T> log2(const T x) noexcept¶ Compile-time binary logarithm function.
- Parameters
x – a real-valued input.
- Returns
\( \log_2(x) \) using
\[ \log_{2}(x) = \frac{\log_e(x)}{\log_e(2)} \]
-
template<typename T>
constexpr return_t<T> log10(const T x) noexcept¶ Compile-time common logarithm function.
- Parameters
x – a real-valued input.
- Returns
\( \log_{10}(x) \) using
\[ \log_{10}(x) = \frac{\log_e(x)}{\log_e(10)} \]
-
template<typename T1, typename T2>
constexpr common_t<T1, T2> max(const T1 x, const T2 y) noexcept¶ Compile-time pairwise maximum function.
- Parameters
x – a real-valued input.
y – a real-valued input.
- Returns
Computes the maximum between
x
andy
, wherex
andy
have the same type (e.g.,int
,double
, etc.)
-
template<typename T1, typename T2>
constexpr common_t<T1, T2> min(const T1 x, const T2 y) noexcept¶ Compile-time pairwise minimum function.
- Parameters
x – a real-valued input.
y – a real-valued input.
- Returns
Computes the minimum between
x
andy
, wherex
andy
have the same type (e.g.,int
,double
, etc.)
-
template<typename T1, typename T2>
constexpr common_t<T1, T2> pow(const T1 base, const T2 exp_term) noexcept¶ Compile-time power function.
- Parameters
base – a real-valued input.
exp_term – a real-valued input.
- Returns
Computes
base
raised to the powerexp_term
. In the case whereexp_term
is integral-valued, recursion by squaring is used, otherwise \( \text{base}^{\text{exp\_term}} = e^{\text{exp\_term} \log(\text{base})} \)
-
template<typename T>
constexpr return_t<T> round(const T x) noexcept¶ Compile-time round function.
- Parameters
x – a real-valued input.
- Returns
computes the rounding value of the input.
-
template<typename T>
constexpr bool signbit(const T x) noexcept¶ Compile-time sign bit detection function.
- Parameters
x – a real-valued input
- Returns
return true if
x
is negative, otherwise return false.
-
template<typename T>
constexpr int sgn(const T x) noexcept¶ Compile-time sign function.
- Parameters
x – a real-valued input
- Returns
a value \( y \) such that
\[ y = \begin{cases} 1 \ &\text{ if } x > 0 \\ 0 \ &\text{ if } x = 0 \\ -1 \ &\text{ if } x < 0 \end{cases} \]
-
template<typename T>
constexpr return_t<T> sqrt(const T x) noexcept¶ Compile-time square-root function.
- Parameters
x – a real-valued input.
- Returns
Computes \( \sqrt{x} \) using a Newton-Raphson approach.