2
3
4
5
6
7
8
11#ifndef _MSTD_MATH_FUNCTIONS_HPP_
12 #define _MSTD_MATH_FUNCTIONS_HPP_
14 #include <mstd/config.hpp>
17_MSTD_WARNING(
"this is only available for c++17 and greater!");
20 #include <mstd/arithmetic_types.hpp>
26 template<
class T, std::enable_if_t<std::is_arithmetic_v<T>,
bool> =
true>
30 return static_cast<
T>((
static_cast<
T>(0) <
x) - (
x <
static_cast<
T>(0)));
32 else {
return static_cast<
T>(0) !=
x; }
38 template<
class T, std::enable_if_t<std::is_arithmetic_v<T>,
bool> =
true>
47 template<
class T, std::enable_if_t<std::is_arithmetic_v<T>,
bool> =
true>
50 const T& expectedEnd)
noexcept {
57 template<
class T, std::enable_if_t<std::is_arithmetic_v<T>,
bool> =
true>
67 template<
class T, std::enable_if_t<std::is_arithmetic_v<T>,
bool> =
true>
79 template<
class AT,
class BT,
class EpsT, std::enable_if_t<
mstd::are_floating_points_v<AT, BT, EpsT>,
bool> =
true>
89 template<
class AT,
class BT,
class EpsT =
double,
90 std::enable_if_t<
mstd::are_arithmetic_v<AT, BT> && std::is_floating_point_v<EpsT>,
bool> =
true>
96 else {
return a ==
b; }
102 template<
class AT,
class BT,
class EpsT =
double,
103 std::enable_if_t<
mstd::are_arithmetic_v<AT, BT> && std::is_floating_point_v<EpsT>,
bool> =
true>
112 template<
class T, std::enable_if_t<std::is_arithmetic_v<T>,
bool> =
true>
121 template<
class T, std::enable_if_t<std::is_arithmetic_v<T>,
bool> =
true>
133 auto y = std::bit_cast<
float>(magi_number - (std::bit_cast<uint32_t>(number) >> 1));
135 auto yi = magi_number - ((*
reinterpret_cast<uint32_t*>(&number)) >> 1);
136 auto y = *
reinterpret_cast<
float*>(&yi);
138 return y * (one_half - (number * half * y * y));
#define _MSTD_HAS_CXX17
Definition config.hpp:45
#define _MSTD_CONSTEXPR17
Definition config.hpp:76
#define _MSTD_HAS_CXX20
Definition config.hpp:52
#define _MSTD_INLINE17
Definition config.hpp:83
#define _MSTD_CONSTEXPR20
Definition config.hpp:84
Definition arithmetic_types.hpp:23
_MSTD_INLINE17 _MSTD_CONSTEXPR20 T deg_to_rad(const T &angle) noexcept
Definition math_functions.hpp:59
static _MSTD_CONSTEXPR17 const float default_epsilon
Definition math_functions.hpp:74
_MSTD_INLINE17 _MSTD_CONSTEXPR20 bool is_not_equal(const AT &a, const BT &b, const EpsT &eps=default_epsilon)
Definition math_functions.hpp:105
_MSTD_INLINE17 _MSTD_CONSTEXPR20 bool is_equal(const AT &a, const BT &b, const EpsT &eps=default_epsilon)
Definition math_functions.hpp:92
_MSTD_INLINE17 _MSTD_CONSTEXPR20 T fract(const T &x)
Definition math_functions.hpp:123
_MSTD_INLINE17 _MSTD_CONSTEXPR20 T signum(const T &x) noexcept
Definition math_functions.hpp:28
_MSTD_INLINE17 _MSTD_CONSTEXPR20 T rad_to_deg(const T &rad) noexcept
Definition math_functions.hpp:69
_MSTD_INLINE17 _MSTD_CONSTEXPR20 T saturate(const T &a) noexcept
Definition math_functions.hpp:114
_MSTD_INLINE17 _MSTD_CONSTEXPR20 T remap(const T &input, const T &currStart, const T &currEnd, const T &expectedStart, const T &expectedEnd) noexcept
Definition math_functions.hpp:49
_MSTD_INLINE17 _MSTD_CONSTEXPR20 bool epsilon_equal(const AT &a, const BT &b, const EpsT &epsilon=default_epsilon) noexcept
Definition math_functions.hpp:81
_MSTD_INLINE17 _MSTD_CONSTEXPR20 float q_rsqrt(float number) noexcept
Definition math_functions.hpp:128
_MSTD_INLINE17 _MSTD_CONSTEXPR20 T step(const T &edge, const T &x) noexcept
Definition math_functions.hpp:40