Skip to content

Add mul_hi #53855

@LilithHafner

Description

@LilithHafner

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestsgood first issueIndicates a good issue for first-time contributors to Juliahelp wantedIndicates that a maintainer wants help on an issue or pull requestmathsMathematical functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions