Skip to content

Overflows are ignored in some cases when checked-converting from Int128 to SignedInteger #99489

@skyoxZ

Description

@skyoxZ

Description

public static explicit operator checked long(Int128 value)
{
if (~value._upper == 0)
{
long lower = (long)value._lower;
return lower;
}

Overflows are ignored when lower >= 0.

Search if (~value._upper == 0) in that file to find more.

Reproduction Steps

Int128 a = new(ulong.MaxValue, 42);
var b = checked((long)a);
Console.WriteLine(b);

Expected behavior

OverflowException

Actual behavior

42

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions