Skip to content

Add mul_hi #53855

Open
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

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestsgood first issueIndicates a good issue for first-time contributors to JuliamathsMathematical functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions