MCPcopy Create free account
hub / github.com/apache/arrow / ModuloWithOverflowGeneric

Function ModuloWithOverflowGeneric

cpp/src/arrow/util/int_util_overflow.h:141–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139
140template <typename Int>
141[[nodiscard]] bool ModuloWithOverflowGeneric(Int u, Int v, Int* out) {
142 if (v == 0) {
143 *out = Int{};
144 return true;
145 }
146 // INT_MIN % -1 is undefined behavior (the quotient is not representable) and
147 // traps on some targets, but the mathematical result is 0.
148 if constexpr (std::is_signed_v<Int>) {
149 constexpr auto kMin = std::numeric_limits<Int>::min();
150 if (u == kMin && v == -1) {
151 *out = 0;
152 return true;
153 }
154 }
155 *out = u % v;
156 return false;
157}
158
159// Define non-generic versions of the above so as to benefit from automatic
160// integer conversion, to allow for mixed-type calls such as

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected