Basic math functions¶
abs
function¶
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
T1 abs(const T1 &x)
Returns the absolute value of x.
absmax
function¶
template <typename T1, typename T2,
KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = std::common_type_t<T1, T2>>
Tout absmax(const T1 &x, const T2 &y)
Returns the greater in magnitude of two values.
absmin
function¶
template <typename T1, typename T2,
KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = std::common_type_t<T1, T2>>
Tout absmin(const T1 &x, const T2 &y)
Returns the smaller in magnitude of two values.
add
function¶
template <typename T1, typename T2, typename... Ts,
KFR_ENABLE_IF(is_numeric_args<T1, T2, Ts...>)>
constexpr std::common_type_t<T1, T2, Ts...>
add(const T1 &x, const T2 &y, const Ts &...rest)
Returns sum of all the arguments passed to a function.
bitwiseand
function¶
template <typename T1, typename T2>
std::common_type_t<T1, T2> bitwiseand(const T1 &x,
const T2 &y)
Bitwise And
bitwiseandnot
function¶
template <typename T1, typename T2>
std::common_type_t<T1, T2> bitwiseandnot(const T1 &x,
const T2 &y)
Bitwise And-Not
bitwisenot
function¶
template <typename T1> T1 bitwisenot(const T1 &x)
Bitwise Not
bitwiseor
function¶
template <typename T1, typename T2>
std::common_type_t<T1, T2> bitwiseor(const T1 &x,
const T2 &y)
Bitwise Or
bitwisexor
function¶
template <typename T1, typename T2>
std::common_type_t<T1, T2> bitwisexor(const T1 &x,
const T2 &y)
Bitwise Xor (Exclusive Or)
clamp
function¶
template <typename T1, typename T2, typename T3,
KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>),
typename Tout = std::common_type_t<T1, T2, T3>>
Tout clamp(const T1 &x, const T2 &lo, const T3 &hi)
Returns the first argument clamped to a range [lo, hi]
template <typename T1, typename T2,
KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = std::common_type_t<T1, T2>>
Tout clamp(const T1 &x, const T2 &hi)
Returns the first argument clamped to a range [0, hi]
cub
function¶
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
constexpr inline T1 cub(const T1 &x)
Returns cube of x.
div
function¶
template <typename T1, typename T2,
typename Tout = std::common_type_t<T1, T2>>
Tout div(const T1 &x, const T2 &y)
Division
fmadd
function¶
template <typename T1, typename T2, typename T3>
constexpr std::common_type_t<T1, T2, T3>
fmadd(const T1 &x, const T2 &y, const T3 &z)
Fused Multiply-Add
fmsub
function¶
template <typename T1, typename T2, typename T3>
constexpr std::common_type_t<T1, T2, T3>
fmsub(const T1 &x, const T2 &y, const T3 &z)
Fused Multiply-Sub
horner
function¶
template <typename T1, typename... Ts,
KFR_ENABLE_IF(is_numeric_args<T1, Ts...>)>
constexpr std::common_type_t<T1, Ts...>
horner(const T1 &x, const Ts &...c)
Calculate polynomial using Horner's method
horner(x, 1, 2, 3)
is equivalent to \(3x^2 + 2x + 1\)
horner_even
function¶
template <typename T1, typename... Ts,
KFR_ENABLE_IF(is_numeric_args<T1, Ts...>)>
constexpr std::common_type_t<T1, Ts...>
horner_even(const T1 &x, const Ts &...c)
Calculate polynomial using Horner's method (even powers)
horner_even(x, 1, 2, 3)
is equivalent to \(3x^4 + 2x^2 + 1\)
horner_odd
function¶
template <typename T1, typename... Ts,
KFR_ENABLE_IF(is_numeric_args<T1, Ts...>)>
constexpr std::common_type_t<T1, Ts...>
horner_odd(const T1 &x, const Ts &...c)
Calculate polynomial using Horner's method (odd powers)
horner_odd(x, 1, 2, 3)
is equivalent to \(3x^5 + 2x^3 + 1x\)
ipow
function¶
template <typename T>
constexpr inline T ipow(const T &x, int base)
Raise x to the power base \(x^{base}\)
CHECK( ipow( 10, 3 ) == 1000 );
CHECK( ipow( 0.5, 2 ) == 0.25 );
max
function¶
template <typename T1, typename T2,
KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = std::common_type_t<T1, T2>>
Tout max(const T1 &x, const T2 &y)
Returns the greater of two values.
min
function¶
template <typename T1, typename T2,
KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = std::common_type_t<T1, T2>>
Tout min(const T1 &x, const T2 &y)
Returns the smaller of two values.
mix
function¶
template <typename T1, typename T2, typename T3,
KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>)>
constexpr std::common_type_t<T1, T2, T3>
mix(const T1 &c, const T2 &x, const T3 &y)
Linear blend of x
and y
(c
must be in the range 0...+1)
Returns x + ( y - x ) * c
mixs
function¶
template <typename T1, typename T2, typename T3,
KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>)>
constexpr std::common_type_t<T1, T2, T3>
mixs(const T1 &c, const T2 &x, const T3 &y)
Linear blend of x
and y
(c
must be in the range -1...+1)
mod
function¶
template <typename T1, typename T2,
typename Tout = std::common_type_t<T1, T2>>
Tout mod(const T1 &x, const T2 &y)
Modulo
mul
function¶
template <typename T1, typename T2, typename... Ts>
constexpr std::common_type_t<T1, T2, Ts...>
mul(const T1 &x, const T2 &y, const Ts &...rest)
Returns product of all the arguments passed to a function.
neg
function¶
template <typename T1> inline T1 neg(const T1 &x)
Negation
reciprocal
function¶
template <typename T> constexpr T reciprocal(const T &x)
Calculate Multiplicative Inverse of x
Returns 1/x
rem
function¶
template <typename T1, typename T2,
typename Tout = std::common_type_t<T1, T2>>
Tout rem(const T1 &x, const T2 &y)
Remainder
rol
function¶
template <typename T1, typename T2>
T1 rol(const T1 &left, const T2 &right)
Bitwise Left Rotate
ror
function¶
template <typename T1, typename T2>
T1 ror(const T1 &left, const T2 &right)
Bitwise Right Rotate
select
function¶
template <
typename T1, size_t N, typename T2, typename T3,
KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>),
typename Tout = subtype<std::common_type_t<T2, T3>>>
vec<Tout, N> select(const mask<T1, N> &m, const T2 &x,
const T3 &y)
Returns x if m is true, otherwise return y. Order of the arguments is same as in ternary operator.
return m ? x : y
shl
function¶
template <typename T1, typename T2>
T1 shl(const T1 &left, const T2 &right)
Bitwise Left shift
shr
function¶
template <typename T1, typename T2>
T1 shr(const T1 &left, const T2 &right)
Bitwise Right shift
sqr
function¶
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
constexpr inline T1 sqr(const T1 &x)
Returns square of x.
sqrsum
function¶
template <typename T1, typename... Ts>
constexpr inline std::common_type_t<T1, Ts...>
sqrsum(const T1 &x, const Ts &...rest)
Return square of the sum of all arguments
CHECK(sqrsum(1,2,3) == 36);
sqrt
function¶
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
flt_type<T1> sqrt(const T1 &x)
Returns the positive square root of the x. \(\sqrt{x}\)
swapbyteorder
function¶
template <typename T> T swapbyteorder(const T &x)
Swap byte order
Auto-generated from sources, Revision 5191a48df06ea47104ca67db19fa82058d09c20a, https://github.com/kfrlib/kfr/blob/5191a48df06ea47104ca67db19fa82058d09c20a/include/kfr/