Skip to content

Commit

Permalink
Revert "Use Unsafe.BitCast for Int128UInt128 operators (#104506
Browse files Browse the repository at this point in the history
…)" (#106430)

This reverts commit 01dbf51.
  • Loading branch information
stephentoub authored Aug 15, 2024
1 parent 042cc95 commit 0396978
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Int128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public static explicit operator checked ulong(Int128 value)
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to a <see cref="UInt128" />.</returns>
[CLSCompliant(false)]
public static explicit operator UInt128(Int128 value) => Unsafe.BitCast<Int128, UInt128>(value);
public static explicit operator UInt128(Int128 value) => new UInt128(value._upper, value._lower);

/// <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>
/// <param name="value">The value to convert.</param>
Expand All @@ -438,7 +438,7 @@ public static explicit operator checked UInt128(Int128 value)
{
ThrowHelper.ThrowOverflowException();
}
return Unsafe.BitCast<Int128, UInt128>(value);
return new UInt128(value._upper, value._lower);
}

/// <summary>Explicitly converts a 128-bit signed integer to a <see cref="UIntPtr" /> value.</summary>
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/UInt128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public static explicit operator checked long(UInt128 value)
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to a <see cref="Int128" />.</returns>
[CLSCompliant(false)]
public static explicit operator Int128(UInt128 value) => Unsafe.BitCast<UInt128, Int128>(value);
public static explicit operator Int128(UInt128 value) => new Int128(value._upper, value._lower);

/// <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>
/// <param name="value">The value to convert.</param>
Expand All @@ -357,7 +357,7 @@ public static explicit operator checked Int128(UInt128 value)
{
ThrowHelper.ThrowOverflowException();
}
return Unsafe.BitCast<UInt128, Int128>(value);
return new Int128(value._upper, value._lower);
}

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

0 comments on commit 0396978

Please sign in to comment.