Skip to content

NET7 Int128, UInt128 - bugs in ToString  #75072

Description

@c-ohle

Description

Wrong ToString results for Int128, UInt128

Self explaining, in UInt128ToDecStr(UInt128) since CountDigits ignores the highword.
CountDigits and its variants should be rewritten as it is the most stupid and slowest implementation I ever saw.

image

Reproduction Steps

var x = Int128.MaxValue / Int64.MaxValue; var ss = x.ToString(); // => "2"
var y = UInt128.MaxValue / UInt64.MaxValue; var sy = y.ToString(); // => "1"

Expected behavior

var x = Int128.MaxValue / Int64.MaxValue; var ss = x.ToString(); // => "18446744073709551618"
var y = UInt128.MaxValue / UInt64.MaxValue; var sy = y.ToString(); // => "18446744073709551617"

Actual behavior

var x = Int128.MaxValue / Int64.MaxValue; var ss = x.ToString(); // => "2"
var y = UInt128.MaxValue / UInt64.MaxValue; var sy = y.ToString(); // => "1"

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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