25#include "iceberg/result.h"
30inline constexpr int64_t FloorDiv(int64_t dividend, int64_t divisor) {
31 const auto quotient = dividend / divisor;
32 if ((dividend ^ divisor) < 0 && quotient * divisor != dividend) {
38inline Result<int64_t> MultiplyExact(int64_t lhs, int64_t rhs) {
39 const auto result =
static_cast<int128_t
>(lhs) *
static_cast<int128_t
>(rhs);
40 if (result > std::numeric_limits<int64_t>::max() ||
41 result < std::numeric_limits<int64_t>::min()) [[unlikely]] {
42 return InvalidArgument(
"Long overflow when multiplying {} by {}", lhs, rhs);
44 return static_cast<int64_t
>(result);