![]() |
Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
|
Division and modulus using uint32_t numerators and denominators. More...
Division and modulus using uint32_t numerators and denominators.
Definition at line 137 of file constant_divisor.h.
#include <constant_divisor.h>
Public Types | |
using | value_type = uint32_t |
Public Types inherited from util::math::internal::ConstantDivisorBase< uint32_t, uint64_t, ConstantDivisor< uint32_t > > | |
using | value_type |
Public Member Functions | |
ConstantDivisor (value_type denominator) | |
REQUIRES: denominator > 1. | |
value_type | div (value_type numerator) const |
value_type | mod (value_type n) const |
Public Member Functions inherited from util::math::internal::ConstantDivisorBase< uint32_t, uint64_t, ConstantDivisor< uint32_t > > | |
ConstantDivisorBase (uint64_t magic, value_type denominator) | |
value_type | mod (value_type numerator) const |
value_type | denominator () const |
Friends | |
value_type | operator/ (value_type a, const ConstantDivisor &b) |
value_type | operator% (value_type a, const ConstantDivisor &b) |
Additional Inherited Members | |
Protected Types inherited from util::math::internal::ConstantDivisorBase< uint32_t, uint64_t, ConstantDivisor< uint32_t > > | |
using | MagicValueType |
Protected Attributes inherited from util::math::internal::ConstantDivisorBase< uint32_t, uint64_t, ConstantDivisor< uint32_t > > | |
uint64_t | magic_ |
using util::math::ConstantDivisor< uint32_t >::value_type = uint32_t |
Definition at line 141 of file constant_divisor.h.
|
explicit |
REQUIRES: denominator > 1.
If we hardcode shift_amount to 32, the 32-bit formula is: magic_number = 2 ^ 64 / d value / d = value * magic_number >> 64
One caveat is that for d == 1, magic_number takes 65 bits overflowing a uint64_t. So, we again disallow inputs with d == 1.
Definition at line 39 of file constant_divisor.cc.
|
inline |
Definition at line 146 of file constant_divisor.h.
|
inline |
Definition at line 66 of file constant_divisor.h.
|
friend |
Definition at line 72 of file constant_divisor.h.
|
friend |
Definition at line 68 of file constant_divisor.h.