Not Enough Math
Lightweight zero-dependency C++ math library
Loading...
Searching...
No Matches
unsafe_mode.hpp
Go to the documentation of this file.
1/*
2
3This is purely design documentation ideas on how to make customizable, optimized and neat safety handling features in NEM. This is a WIP code that is further to be analyzed, tested and designed
4
5struct safe_t { explicit constexpr safe_t() = default; };
6struct unsafe_t { explicit constexpr unsafe_t() = default; };
7
8inline constexpr safe_t safe{};
9inline constexpr unsafe_t unsafe{};
10
14template <nem::scalar_type T> constexpr T mod(T a, T b, nem::unsafe_t)
15{
16 const T absb = nem::abs(b);
17 const T v = a - nem::floor(a / b) * b;
18 const T r = v < 0 ? v + absb : v;
19 return nem::equal(r, absb) ? (T)0.0 : r;
20}
21
25template <nem::scalar_type T> constexpr T mod(T a, T b, nem::safe_t = nem::safe)
26{
27 if (nem::is_zero(b))
28 {
29 return nem::error::invalid_result<T>(nem::error::Kind::DivisionByZero);
30 }
31 return nem::mod(a, b, nem::unsafe);
32}
33
34*/