MCPcopy Create free account
hub / github.com/comaps/comaps / ModularCast

Function ModularCast

libs/routing/coding.hpp:70–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68// (modulo 2^n where n is the number of bits used to represent the unsigned type)
69template <typename Unsigned, typename Signed = std::make_signed_t<Unsigned>>
70Signed ModularCast(Unsigned value)
71{
72 static_assert(std::is_unsigned<Unsigned>::value, "T should be an unsigned type");
73
74 if (value <= static_cast<Unsigned>(std::numeric_limits<Signed>::max()))
75 return static_cast<Signed>(value);
76
77 auto constexpr minSignedT = std::numeric_limits<Signed>::min();
78 return static_cast<Signed>(value - static_cast<Unsigned>(minSignedT)) + minSignedT;
79}
80
81// Encodes current as delta compared with prev.
82template <typename T, typename UnsignedT = std::make_unsigned_t<T>>

Callers 2

EncodeZigZagDeltaFunction · 0.85
UNIT_TESTFunction · 0.85

Calls

no outgoing calls

Tested by 1

UNIT_TESTFunction · 0.68