From d7c4c84e4816106a91e9c71ebd279466b6b301b9 Mon Sep 17 00:00:00 2001 From: Abhishek Dahad Date: Thu, 20 Aug 2026 12:09:47 -0700 Subject: [PATCH] Replace FloatUtils Conversion to Integral types through unions with typecasts --- src/Microsoft.ML.Core/Utilities/FloatUtils.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.ML.Core/Utilities/FloatUtils.cs b/src/Microsoft.ML.Core/Utilities/FloatUtils.cs index 8498ac8a79..a8b2d1ce53 100644 --- a/src/Microsoft.ML.Core/Utilities/FloatUtils.cs +++ b/src/Microsoft.ML.Core/Utilities/FloatUtils.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.Runtime.InteropServices; using Microsoft.ML.Runtime; +using System.Runtime.CompilerServices; namespace Microsoft.ML.Internal.Utilities { @@ -400,16 +401,12 @@ public void Truncate() public static ulong GetBits(double x) { - var bits = default(DoubleBits); - bits.Float = x; - return bits.Bits; + return Unsafe.As(ref x); } public static uint GetBits(float x) { - var bits = default(SingleBits); - bits.Float = x; - return bits.Bits; + return Unsafe.As(ref x); } public static double FromBits(ulong bits)