numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
num_collect::constants Namespace Reference

Namespace of constexpr variables and functions. More...

Namespaces

namespace  impl
 Namespace of internal implementations.
 

Functions

template<typename T >
constexpr auto cbrt (T x)
 Calculate cubic root \( \sqrt[3]{x} \).
 
template<typename T >
constexpr auto ceil (T x) -> T
 Calculate the smallest integer not less than x, \( \lceil x \rceil \).
 
template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
constexpr auto exp (T x) -> T
 Calculate exponential function \( e^x \).
 
template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
constexpr auto expm1 (T x) -> T
 Calculate exponential function minus one \( e^x - 1 \).
 
template<typename T >
constexpr auto floor (T x) -> T
 Calculate the largest integer not greater than x, \( \lfloor x \rfloor \).
 
template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
constexpr auto log (T x) -> T
 Calculate logarithm \( \log(x) \).
 
template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
constexpr auto log1p (T x) -> T
 Calculate natural logarithm of 1 + x, \( \log(1 + x) \).
 
template<typename B , typename E , std::enable_if_t< std::is_integral_v< E >, void * > = nullptr>
constexpr auto pow (B base, E exp) -> B
 Calculate power \( {base}^{exp} \).
 
template<typename T , std::enable_if_t< std::is_floating_point_v< T >, void * > = nullptr>
constexpr auto pow (T base, T exp) -> T
 Calculate power \( {base}^{exp} \).
 
template<typename F , typename I , std::enable_if_t< std::is_floating_point_v< F > &&std::is_integral_v< I >, void * > = nullptr>
constexpr auto root (F x, I n) -> F
 Calculate n-th root \( \sqrt[n]{x} \).
 
template<typename IB , typename IE , std::enable_if_t< std::is_integral_v< IB > &&std::is_integral_v< IE >, void * > = nullptr>
constexpr auto root (IB x, IE n) -> double
 Calculate n-th root \( \sqrt[n]{x} \).
 
template<typename F , std::enable_if_t< std::is_floating_point_v< F >, void * > = nullptr>
constexpr auto sqrt (F x) -> F
 Calculate square root \( \sqrt{x} \).
 
template<typename I , std::enable_if_t< std::is_integral_v< I >, void * > = nullptr>
constexpr auto sqrt (I x) -> double
 Calculate square root \( \sqrt{x} \).
 
template<typename T >
constexpr auto trunc (T x) -> T
 Truncate the decimal part of a number x.
 

Variables

template<typename T >
constexpr T half = static_cast<T>(0.5)
 Value 0.5.
 
template<typename T >
constexpr T napier = static_cast<T>(NUM_COLLECT_NAPIER)
 Value of Napier's constant (or Euler's number), \( e = 2.7182818284590452 \ldots \).
 
template<typename T >
constexpr T one = static_cast<T>(1)
 Value 1.
 
template<typename T >
constexpr T pi = static_cast<T>(NUM_COLLECT_PI)
 Value of pi, \( \pi = 3.141592653589793238462 \dots \).
 
constexpr double pid = pi<double>
 Value of pi.
 
constexpr float pif = pi<float>
 Value of pi.
 
template<typename T >
constexpr T two = static_cast<T>(2)
 Value 2.
 
template<typename T >
constexpr T zero = static_cast<T>(0)
 Value 0.
 

Detailed Description

Namespace of constexpr variables and functions.

Function Documentation

◆ cbrt()

template<typename T >
auto num_collect::constants::cbrt ( T x)
constexpr

Calculate cubic root \( \sqrt[3]{x} \).

This function calculates similar values as cbrt function in C++ standard library in constexpr.

Template Parameters
TValue type.
Parameters
[in]xValue to calculate cubic root of.
Returns
Cubic root.

Definition at line 38 of file cbrt.h.

◆ ceil()

template<typename T >
auto num_collect::constants::ceil ( T x) -> T
constexpr

Calculate the smallest integer not less than x, \( \lceil x \rceil \).

This function calculates similar values as ceil function in C++ standard library in constexpr.

Note
This function assumes that inputs are floating-point numbers.
Template Parameters
TNumber type.
Parameters
[in]xNumber.
Returns
Smallest integer not less than x.

Definition at line 43 of file ceil.h.

◆ exp()

template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
auto num_collect::constants::exp ( T x) -> T
constexpr

Calculate exponential function \( e^x \).

This function calculates similar values as exp function in C++ standard library in constexpr.

Template Parameters
TNumber type.
Parameters
[in]xNumber.
Returns
Exponential function value.

Definition at line 46 of file exp.h.

◆ expm1()

template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
auto num_collect::constants::expm1 ( T x) -> T
constexpr

Calculate exponential function minus one \( e^x - 1 \).

This function calculates similar values as expm1 function in C++ standard library in constexpr.

This function has following optimization for small values:

  • for \( 0 \le x \le 1 \), Maclaurin series for \( e^x - 1 \) is used.
  • for \( -1 \le x < 0 \), \( e^x - 1 = - (e^{-x} - 1) / e^{-x} \) is calculated.
Template Parameters
TNumber type.
Parameters
[in]xNumber.
Returns
Exponential function minus one.

Definition at line 49 of file expm1.h.

◆ floor()

template<typename T >
auto num_collect::constants::floor ( T x) -> T
constexpr

Calculate the largest integer not greater than x, \( \lfloor x \rfloor \).

This function calculates similar values as floor function in C++ standard library in constexpr.

Note
This function assumes that inputs are floating-point numbers.
Template Parameters
TNumber type.
Parameters
[in]xNumber.
Returns
Largest integer not greater than x.

Definition at line 43 of file floor.h.

◆ log()

template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
auto num_collect::constants::log ( T x) -> T
constexpr

Calculate logarithm \( \log(x) \).

This function calculates similar values as log function in C++ standard library in constexpr.

Template Parameters
TNumber type.
Parameters
[in]xNumber.
Returns
Logarithm

Definition at line 43 of file log.h.

◆ log1p()

template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
auto num_collect::constants::log1p ( T x) -> T
constexpr

Calculate natural logarithm of 1 + x, \( \log(1 + x) \).

This function calculates similar values as log1p function in C++ standard library in constexpr.

This function can calculate natural logarithm of numbers near to 1 more accurately.

Template Parameters
TNumber type.
Parameters
[in]xNumber.
Returns
Logarithm of 1 - x.

Definition at line 47 of file log1p.h.

◆ pow() [1/2]

template<typename B , typename E , std::enable_if_t< std::is_integral_v< E >, void * > = nullptr>
auto num_collect::constants::pow ( B base,
E exp ) -> B
constexpr

Calculate power \( {base}^{exp} \).

This function calculates similar values as pow function in C++ standard library in constexpr.

Template Parameters
BBase type.
EExponent type.
Parameters
[in]baseBase.
[in]expExponent.
Returns
Power.

Definition at line 47 of file pow.h.

◆ pow() [2/2]

template<typename T , std::enable_if_t< std::is_floating_point_v< T >, void * > = nullptr>
auto num_collect::constants::pow ( T base,
T exp ) -> T
constexpr

Calculate power \( {base}^{exp} \).

This function calculates similar values as pow function in C++ standard library in constexpr.

Template Parameters
TNumber type.
Parameters
[in]baseBase.
[in]expExponent.
Returns
Power.

Definition at line 70 of file pow.h.

◆ root() [1/2]

template<typename F , typename I , std::enable_if_t< std::is_floating_point_v< F > &&std::is_integral_v< I >, void * > = nullptr>
auto num_collect::constants::root ( F x,
I n ) -> F
constexpr

Calculate n-th root \( \sqrt[n]{x} \).

Template Parameters
FValue type.
IInteger type for n.
Parameters
[in]xValue to calculate n-th root of.
[in]nExponent.
Returns
n-th root of x.

Definition at line 44 of file root.h.

◆ root() [2/2]

template<typename IB , typename IE , std::enable_if_t< std::is_integral_v< IB > &&std::is_integral_v< IE >, void * > = nullptr>
auto num_collect::constants::root ( IB x,
IE n ) -> double
constexpr

Calculate n-th root \( \sqrt[n]{x} \).

Template Parameters
IBValue type.
IEInteger type for n.
Parameters
[in]xValue to calculate n-th root of.
[in]nExponent.
Returns
n-th root of x.

Definition at line 86 of file root.h.

◆ sqrt() [1/2]

template<typename F , std::enable_if_t< std::is_floating_point_v< F >, void * > = nullptr>
auto num_collect::constants::sqrt ( F x) -> F
constexpr

Calculate square root \( \sqrt{x} \).

This function calculates similar values as sqrt function in C++ standard library in constexpr.

Template Parameters
FValue type.
Parameters
[in]xValue to calculate square root of.
Returns
Square root.

Definition at line 44 of file sqrt.h.

◆ sqrt() [2/2]

template<typename I , std::enable_if_t< std::is_integral_v< I >, void * > = nullptr>
auto num_collect::constants::sqrt ( I x) -> double
constexpr

Calculate square root \( \sqrt{x} \).

This function calculates similar values as sqrt function in C++ standard library in constexpr.

Template Parameters
IValue type.
Parameters
[in]xValue to calculate square root of.
Returns
Square root.

Definition at line 78 of file sqrt.h.

◆ trunc()

template<typename T >
auto num_collect::constants::trunc ( T x) -> T
constexpr

Truncate the decimal part of a number x.

This function calculates similar values as trunc function in C++ standard library in constexpr.

Note
This function assumes that inputs are floating-point numbers.
Template Parameters
TNumber type.
Parameters
[in]xNumber to truncate.
Returns
Truncated number.

Definition at line 43 of file trunc.h.

Variable Documentation

◆ half

template<typename T >
T num_collect::constants::half = static_cast<T>(0.5)
constexpr

Value 0.5.

Template Parameters
TValue type.

Definition at line 30 of file half.h.

◆ napier

template<typename T >
T num_collect::constants::napier = static_cast<T>(NUM_COLLECT_NAPIER)
constexpr

Value of Napier's constant (or Euler's number), \( e = 2.7182818284590452 \ldots \).

Template Parameters
TValue type.

Definition at line 41 of file napier.h.

◆ one

template<typename T >
T num_collect::constants::one = static_cast<T>(1)
constexpr

Value 1.

Template Parameters
TValue type.

Definition at line 30 of file one.h.

◆ pi

template<typename T >
T num_collect::constants::pi = static_cast<T>(NUM_COLLECT_PI)
constexpr

Value of pi, \( \pi = 3.141592653589793238462 \dots \).

Template Parameters
TValue type.

Definition at line 40 of file pi.h.

◆ pid

double num_collect::constants::pid = pi<double>
constexpr

Value of pi.

Definition at line 45 of file pi.h.

◆ pif

float num_collect::constants::pif = pi<float>
constexpr

Value of pi.

Definition at line 50 of file pi.h.

◆ two

template<typename T >
T num_collect::constants::two = static_cast<T>(2)
constexpr

Value 2.

Template Parameters
TValue type.

Definition at line 30 of file two.h.

◆ zero

template<typename T >
T num_collect::constants::zero = static_cast<T>(0)
constexpr

Value 0.

Template Parameters
TValue type.

Definition at line 30 of file zero.h.