12 template <std::
floating_po
int T =
float>
15 uint32_t bits = std::bit_cast<uint32_t>(x);
16 return float(bits) * (1.0f / (1 << 23)) - 126.94269504f;
24 template <std::
floating_po
int T =
float>
27 uint32_t bits = std::bit_cast<uint32_t>(x);
29 int exp = int((bits >> 23) & 0xFF) - 127;
31 bits = (bits & 0x007FFFFF) | 0x3F800000;
32 float m = std::bit_cast<float>(bits);
35 float poly = y * (1.4426950f
39 return float(exp) + poly;
49 template <std::
floating_po
int T =
float, nem::Precision Prec = nem::default_precision>
52 if constexpr (std::is_same_v<T, float>)
71 template <std::
floating_po
int T, nem::Precision Prec = nem::default_precision>
72 constexpr T
log(T base, T value)
85 template <std::
floating_po
int T, nem::Precision Prec = nem::default_precision>
86 constexpr T
ln(T value)
95 template <std::
integral T, nem::Precision Prec = nem::default_precision>
96 constexpr T
log(T base, T value)
105 template <std::
floating_po
int T, nem::Precision Prec = nem::default_precision>
108 if constexpr (std::is_same_v<T, float>)
110 int i =
static_cast<int>(x);
111 float frac = x - float(i);
117 +
frac * 0.0096181f)));
119 uint32_t bits = std::bit_cast<uint32_t>(p);
120 bits += uint32_t(i) << 23;
121 return std::bit_cast<float>(bits);
130 template <nem::scalar_type T, std::
integral E>
134 return (exp % 2 != 0) ? -result : result;
137 template <std::
floating_po
int T, nem::Precision Prec = nem::default_precision>
143 template <std::
floating_po
int T, nem::Precision Prec = nem::default_precision>
179 template <
typename T>
186 if constexpr (std::is_floating_point_v<T>)
188 return static_cast<T
>(nem::intr::_nem_sqrt(value));
190 else if constexpr (std::is_integral_v<T>)
192 return static_cast<T
>(nem::intr::_nem_sqrt(
static_cast<double>(value)));
196 template <std::
floating_po
int T,
int Precision = 20>
207 result = 0.5 * (result + value / result);
212 template <std::
integral T,
int Precision = 20>
213 constexpr T
csqrt(T value)
225 return static_cast<T
>(result);
235 if (b > 65535) b = 65535;
238 if (m*m > x) b = m - 1;
252 for (s = 30; s >= 0; s = s - 3)
255 b = (3*y*(y + 1) + 1) << s;
constexpr nem::Precision mode
T invalid_result(nem::error::Kind kind=Kind::RuntimeError, const char *const msg=nullptr)
constexpr nem::Precision mode
constexpr T LOG2E
log(2, e)
constexpr T pow(T base, E exp)
constexpr T abs(T value) noexcept
constexpr bool is_zero(T a) noexcept
Is a nearly 0? Given an Epsilon > 0, within each all numbers are considered indistinguisable from 0,...
constexpr bool is_zero_or_neg(T a) noexcept
constexpr T frac(T value) noexcept
Returns the fractional part of the floating-point number, with respect to sign 3.5 -> 0....
constexpr T csqrt(T value)
constexpr unsafe_t unsafe
constexpr T round(T value) noexcept
constexpr bool equal(T a, T b) noexcept
Are a and b nearly equal? Given an Epsilon > 0, within each all numbers are considered indistinguisab...
constexpr T log(T base, T value)
constexpr T is_whole(T value)
Is a floating point number whole (same as integer)