Skip to content

{U}Int128 divided by 0 throws wrong exception type #94593

@stephentoub

Description

@stephentoub

Repro:

Int128 a = Int128.MaxValue;
Int128 b = 0;
Int128 result = a / b;

or

UInt128 a = UInt128.MaxValue;
UInt128 b = 0;
UInt128 result = a / b;

If a is set to a small value, like 42, this results in the expected DivideByZeroException. But when a is set to a large value, like MaxValue, it instead throws an ArgumentOutOfRangeException.

Unhandled exception. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
   at System.UInt128.<op_Division>g__DivideSlow|110_2(UInt128 quotient, UInt128 divisor)
   at System.UInt128.op_Division(UInt128 left, UInt128 right)
   at System.Int128.op_Division(Int128 left, Int128 right)

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