Skip to content

Commit 86a209b

Browse files
sdcbgithub-actions
authored andcommitted
Fix UInt128 to double conversion for values in [2^88, 2^104)
Change threshold check from (value._upper >> 24) to (value._upper >> 40) to correctly handle values up to 2^104 in the intermediate precision branch.
1 parent 7357fab commit 86a209b

File tree

1 file changed

+1
-1
lines changed
  • src/libraries/System.Private.CoreLib/src/System

1 file changed

+1
-1
lines changed

src/libraries/System.Private.CoreLib/src/System/UInt128.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public static explicit operator double(UInt128 value)
275275
// for the precision loss that double will have. As such, the lower value effectively drops the
276276
// lowest 24 bits and then or's them back to ensure rounding stays correct.
277277

278-
double lower = BitConverter.UInt64BitsToDouble(TwoPow76Bits | ((ulong)(value >> 12) >> 12) | ((value._lower & 0xFFFFFF) != 0 ? 1UL : 0UL)) - TwoPow76;
278+
double lower = BitConverter.UInt64BitsToDouble(TwoPow76Bits | ((ulong)(value >> 12) >> 12) | (value._lower & 0xFFFFFF)) - TwoPow76;
279279
double upper = BitConverter.UInt64BitsToDouble(TwoPow128Bits | (value._upper >> 12)) - TwoPow128;
280280

281281
return lower + upper;

0 commit comments

Comments
 (0)