Skip to content

Commit 0396978

Browse files
authored
Revert "Use Unsafe.BitCast for Int128UInt128 operators (#104506)" (#106430)
This reverts commit 01dbf51.
1 parent 042cc95 commit 0396978

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public static explicit operator checked ulong(Int128 value)
425425
/// <param name="value">The value to convert.</param>
426426
/// <returns><paramref name="value" /> converted to a <see cref="UInt128" />.</returns>
427427
[CLSCompliant(false)]
428-
public static explicit operator UInt128(Int128 value) => Unsafe.BitCast<Int128, UInt128>(value);
428+
public static explicit operator UInt128(Int128 value) => new UInt128(value._upper, value._lower);
429429

430430
/// <summary>Explicitly converts a 128-bit signed integer to a <see cref="UInt128" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
431431
/// <param name="value">The value to convert.</param>
@@ -438,7 +438,7 @@ public static explicit operator checked UInt128(Int128 value)
438438
{
439439
ThrowHelper.ThrowOverflowException();
440440
}
441-
return Unsafe.BitCast<Int128, UInt128>(value);
441+
return new UInt128(value._upper, value._lower);
442442
}
443443

444444
/// <summary>Explicitly converts a 128-bit signed integer to a <see cref="UIntPtr" /> value.</summary>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public static explicit operator checked long(UInt128 value)
344344
/// <param name="value">The value to convert.</param>
345345
/// <returns><paramref name="value" /> converted to a <see cref="Int128" />.</returns>
346346
[CLSCompliant(false)]
347-
public static explicit operator Int128(UInt128 value) => Unsafe.BitCast<UInt128, Int128>(value);
347+
public static explicit operator Int128(UInt128 value) => new Int128(value._upper, value._lower);
348348

349349
/// <summary>Explicitly converts a 128-bit unsigned integer to a <see cref="Int128" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
350350
/// <param name="value">The value to convert.</param>
@@ -357,7 +357,7 @@ public static explicit operator checked Int128(UInt128 value)
357357
{
358358
ThrowHelper.ThrowOverflowException();
359359
}
360-
return Unsafe.BitCast<UInt128, Int128>(value);
360+
return new Int128(value._upper, value._lower);
361361
}
362362

363363
/// <summary>Explicitly converts a 128-bit unsigned integer to a <see cref="IntPtr" /> value.</summary>

0 commit comments

Comments
 (0)