Skip to content

Use Math.DivRem instead of / % in BigInteger if dividend and divisor are trivial #45230

@KvanTTT

Description

@KvanTTT

Description

Currently, the following code is used:

remainder = dividend._sign % divisor._sign;
return dividend._sign / divisor._sign;

I suggest using the system Math.DivRem. It's a bit faster because it uses only a single division, multiplication, and subtraction instead of two divisions:

int quotient = Math.DivRem(dividend._sign, divisor._sign, out int intRemainder);
remainder = intRemainder;
return quotient;

Moreover, in theory, it can use intrinsics.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions