Open
Description
Get the high bits of the product of two overflowing integers. Like this, but more efficient for 128-bit integers:
function mul_hi(x::T, y::T) where T <: Base.BitInteger
xy = widemul(x, y)
(xy >> 8sizeof(T)) % T
end
mul_lo
is just *
.
mul_hi
for BigInt
could return 0
, false
, or error.
We could define mul_hi_lo
instead to support non-overflowing integer types like SaferIntegers.
From discourse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment