Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
stephentoub opened this issue Nov 10, 2023 · 1 comment · Fixed by #94640
Closed

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

stephentoub opened this issue Nov 10, 2023 · 1 comment · Fixed by #94640

Comments

@stephentoub
Copy link
Member

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)
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 10, 2023
@ghost
Copy link

ghost commented Nov 10, 2023

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

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)
Author: stephentoub
Assignees: -
Labels:

area-System.Numerics

Milestone: -

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Nov 11, 2023
@ghost ghost removed in-pr There is an active PR which will close this issue when it is merged untriaged New issue has not been triaged by the area owner labels Nov 13, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant