Skip to content

Incorrect (U)Int128 to double conversion #122203

@LEI-Hongfaan

Description

@LEI-Hongfaan

Description

When converting 309485009821345068741558271, only 12 digits match.

Reproduction Steps

(double)UInt128.Parse("309485009821345068741558271")

Expected behavior

3.094850098213451E+26

Actual behavior

3.0948500982162654E+26

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

double lower = BitConverter.UInt64BitsToDouble(TwoPow76Bits | ((ulong)(value >> 12) >> 12) | (value._lower & 0xFFFFFF)) - TwoPow76;

Please change (value._lower & 0xFFFFFF) to (0u != (value._lower & 0xFFFFFF) ? 1u : 0u)

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