sandbox
Loading...
Searching...
No Matches
fast_mod.hpp
1
// SPDX-License-Identifier: MIT
2
#ifndef LIBSBX_UTILITY_FAST_MOD_HPP_
3
#define LIBSBX_UTILITY_FAST_MOD_HPP_
4
5
#include <concepts>
6
#include <cmath>
7
8
namespace
sbx::utility {
9
21
template
<std::
unsigned
_
int
egral Value, std::
unsigned
_
int
egral Mod>
22
constexpr
auto
fast_mod(
const
Value value,
const
Mod modulus)
noexcept
-> Value {
23
// return value - (value / modulus) * modulus;
24
return
value < modulus ? value : value % static_cast<Value>(modulus);
25
}
26
27
template
<std::
float
ing_po
int
Type>
28
constexpr
auto
fast_mod(
const
Type value,
const
Type modulus)
noexcept
-> Type {
29
// return value - (value / modulus) * modulus;
30
return
value < modulus ? value : std::fmod(value, modulus);
31
}
32
33
}
// namespace sbx::utility
34
35
#endif
// LIBSBX_UTILITY_FAST_MOD_HPP_
libsbx-utility
libsbx
utility
fast_mod.hpp
Generated by
1.9.5