qxLib
Functions
common.h File Reference
#include <qx/macros/suppress_warnings.h>
#include <qx/typedefs.h>
#include <array>
#include <bitset>
#include <concepts>
#include <limits>
#include <qx/math/common.inl>

Go to the source code of this file.

Functions

template<class T >
constexpr T qx::abs (T value)
 Constexpr absolute value. More...
 
template<class T >
constexpr bool qx::epsilon_equal (T left, T right, T eps=std::numeric_limits< T >::epsilon())
 Constexpr comparison function for a user defined epsilon values. More...
 
template<class T >
constexpr bool qx::epsilon_zero (T value, T eps=std::numeric_limits< T >::epsilon())
 Constexpr comparison with zero for a user defined epsilon values. More...
 
template<class T >
constexpr bool qx::epsilon_less_equal (T left, T right, T eps=std::numeric_limits< T >::epsilon())
 Constexpr comparison function for a user defined epsilon values. More...
 
template<class T >
constexpr bool qx::epsilon_greater_equal (T left, T right, T eps=std::numeric_limits< T >::epsilon())
 Constexpr comparison function for a user defined epsilon values. More...
 
template<std::integral T>
constexpr bool qx::is_odd (T val)
 Check if value is odd. More...
 
template<std::integral T>
constexpr bool qx::is_even (T val)
 Check if value is even. More...
 
constexpr int qx::gcd (int nFirst, int nSecond)
 Greatest common divisor. More...
 
constexpr int qx::lcm (int nFirst, int nSecond)
 Least common multiple. More...
 
template<class T >
double qx::pow (T number, int nPower)
 Power function for integer power. More...
 
template<std::integral I>
qx::maxpot (I nValue)
 Max power of two in integer. More...
 
template<class T , class compare_t = std::less_equal<>>
constexpr bool qx::between (T left, T value, T right, compare_t compare)
 Checks if value is between left and right. More...
 
template<class T , class compare_t = std::less_equal<>>
constexpr bool qx::between (T left, T value, T right)
 Checks if value is between left and right. More...
 

Detailed Description

Author
Khrapov
Date
7.08.2022

Definition in file common.h.

Function Documentation

◆ abs()

template<class T >
constexpr T qx::abs ( value)
constexpr

Constexpr absolute value.

Template Parameters
T- value type
Parameters
value- value
Return values
-absolute value

Definition at line 14 of file common.inl.

◆ between() [1/2]

template<class T , class compare_t = std::less_equal<>>
constexpr bool qx::between ( left,
value,
right 
)
constexpr

Checks if value is between left and right.

Overloading for disabling 4388 warning with Compare instantiation

Template Parameters
T- value type
compare_t- comparator type
Parameters
left- left value
value- value
right- right value
Return values
-true, left <= value <= right

Definition at line 177 of file common.inl.

◆ between() [2/2]

template<class T , class compare_t = std::less_equal<>>
constexpr bool qx::between ( left,
value,
right,
compare_t  compare 
)
constexpr

Checks if value is between left and right.

Template Parameters
T- value type
compare_t- comparator type
Parameters
left- left value
value- value
right- right value
compare- comparator function
Return values
-true, left <= value <= right

Definition at line 153 of file common.inl.

◆ epsilon_equal()

template<class T >
constexpr bool qx::epsilon_equal ( left,
right,
eps = std::numeric_limits<T>::epsilon() 
)
constexpr

Constexpr comparison function for a user defined epsilon values.

Template Parameters
T- value type
Parameters
left- left value
right- right value
eps- epsilon value
Return values
-true if |left - right| < eps

Definition at line 20 of file common.inl.

◆ epsilon_greater_equal()

template<class T >
constexpr bool qx::epsilon_greater_equal ( left,
right,
eps = std::numeric_limits<T>::epsilon() 
)
constexpr

Constexpr comparison function for a user defined epsilon values.

Template Parameters
T- value type
Parameters
left- left value
right- right value
eps- epsilon value
Return values
-true if left > right or |left - right| < eps

Definition at line 38 of file common.inl.

◆ epsilon_less_equal()

template<class T >
constexpr bool qx::epsilon_less_equal ( left,
right,
eps = std::numeric_limits<T>::epsilon() 
)
constexpr

Constexpr comparison function for a user defined epsilon values.

Template Parameters
T- value type
Parameters
left- left value
right- right value
eps- epsilon value
Return values
-true if left < right or |left - right| < eps

Definition at line 32 of file common.inl.

◆ epsilon_zero()

template<class T >
constexpr bool qx::epsilon_zero ( value,
eps = std::numeric_limits<T>::epsilon() 
)
constexpr

Constexpr comparison with zero for a user defined epsilon values.

Template Parameters
T- value type
Parameters
value- user value
eps- epsilon value
Return values
-true if |value| < eps

Definition at line 26 of file common.inl.

◆ gcd()

constexpr int qx::gcd ( int  nFirst,
int  nSecond 
)
constexpr

Greatest common divisor.

Euclid's algorithm based on fact gcd(A, B) == gcd(B, A mod B)

Complexity:
O(log(second))
Parameters
nFirst- first num
nSecond- second num
Return values
-greatest common divisor if first and second > 0, otherwise 0

Definition at line 55 of file common.inl.

◆ is_even()

template<std::integral T>
constexpr bool qx::is_even ( val)
constexpr

Check if value is even.

Template Parameters
T- integral type
Parameters
val- value
Return values
-true if value is even

Definition at line 50 of file common.inl.

◆ is_odd()

template<std::integral T>
constexpr bool qx::is_odd ( val)
constexpr

Check if value is odd.

Template Parameters
T- integral type
Parameters
val- value
Return values
-true if value is odd

Definition at line 44 of file common.inl.

◆ lcm()

constexpr int qx::lcm ( int  nFirst,
int  nSecond 
)
constexpr

Least common multiple.

Complexity:
O(log(second))
Parameters
nFirst- first num
nSecond- second num
Return values
-least common multiple if first and second > 0, otherwise 0

Definition at line 70 of file common.inl.

◆ maxpot()

template<std::integral I>
I qx::maxpot ( nValue)
inline

Max power of two in integer.

Template Parameters
I- Integral type
Parameters
nValue- number
Return values
-max power of two in number

Definition at line 131 of file common.inl.

◆ pow()

template<class T >
double qx::pow ( number,
int  nPower 
)
inline

Power function for integer power.

About 2.22 times (positive powers) 1.7 times (positive and negative powers) 2.33 times (negative powers) faster then std::pow

Complexity:
O(log(power))
Template Parameters
T- Integral or floating point type
Parameters
number- integral of floating point value
nPower- integral power
Return values
-number ^ power

Definition at line 82 of file common.inl.