sandbox
Loading...
Searching...
No Matches
fast_mod.hpp
1#ifndef LIBSBX_UTILITY_FAST_MOD_HPP_
2#define LIBSBX_UTILITY_FAST_MOD_HPP_
3
4#include <concepts>
5#include <cmath>
6
7namespace sbx::utility {
8
19template<std::unsigned_integral Type>
20constexpr auto fast_mod(const Type value, const Type modulus) noexcept -> Type {
21 // return value - (value / modulus) * modulus;
22 return value < modulus ? value : value % modulus;
23}
24
25template<std::floating_point Type>
26constexpr auto fast_mod(const Type value, const Type modulus) noexcept -> Type {
27 // return value - (value / modulus) * modulus;
28 return value < modulus ? value : std::fmod(value, modulus);
29}
30
31} // namespace sbx::utility
32
33#endif // LIBSBX_UTILITY_FAST_MOD_HPP_