Skip to content

NET7 Int128, UInt128 - bugs in ToString  #75072

@c-ohle

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

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