[Breaking change]: Scalar and packed floating point to integer conversions #40234
Closed
1 of 3 tasks
Labels
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 9
Work items for the .NET 9 release
in-pr
This issue will be closed (fixed) by an active pull request.
📌 seQUESTered
Identifies that an issue has been imported into Quest.
Uh oh!
There was an error while loading. Please reload this page.
Description
Behavior of floating point to integer conversions will change following PR dotnet/runtime#97529. The change moves existing non-saturating conversion on
x86/x64
arch to saturating behavior. Hence, following this PR, floating point to integer conversion in .NET will have saturating behavior.Version
.NET 9 RC 1
Previous behavior
Previous behavior --
Case - float/double to long scalar and packed
long.MinValue <= x <= long.MaxValue ---> (long)x
otherwise ---> long.MinValue
Case - float/double to int scalar and packed
int.MinValue <= x <= int.MaxValue ---> (int)x
otherwise ---> int.MinValue
Case - float/double to uint scalar and packed
---> (((long)x << 32) >> 32)
Case - float/double to ulong scalar and packed
x <= 2^63 ---> (long)x
otherwise ---> (long)(x - 2^63) + 2^63
New behavior
Previous behavior --
Case - float/double to long scalar and packed
long.MinValue <= x <= long.MaxValue ---> (long)x
x < long.MinValue ---> long.MinValue
x = NaN ---> 0
x > long.MaxValue ---> long.MaxValue
Case - float/double to int scalar and packed
int.MinValue <= x <= int.MaxValue ---> (int)x
x < int.MinValue ---> int.MinValue
x = NaN ---> 0
x > int.MaxValue ---> int.MaxValue
Case - float/double to uint scalar and packed
0 <= x <= uint.MaxValue ---> (uint)x
x > uint.MaxValue ---> uint.MaxValue
otherwise ---> 0
Case - float/double to ulong scalar and packed
0 <= x <= ulong.MaxValue ---> (ulong)x
x > ulong.MaxValue ---> ulong.MaxValue
otherwise ---> 0
Type of breaking change
Reason for change
.NET wants to standardize all floating point to integer conversions to have saturating behavior. The PR dotnet/runtime#97529 changes behavior of
x86/x64
to support saturating behavior.Recommended action
x86/x64
float/double
toint/uint/long/ulong
Feature area
JIT
Affected APIs
all explicit and implicit casts from floating point to integer.
(long)val
; wheretype(val) = float/double
Vector.ConvertToInt64(Vector<double> val)
(int)val
; wheretype(val) = float/double
Vector.ConvertToInt32(Vector<float> val)
(uint)val
; wheretype(val) = float/double
Vector.ConvertToUInt32(Vector<float> val)
(ulong)val
; wheretype(val) = float/double
Vector.ConvertToUInt64(Vector<double> val)
Associated WorkItem - 307284
The text was updated successfully, but these errors were encountered: