diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.netcore.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.netcore.cs index 0eabb88ce51fa8..adcf52563bebc3 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.netcore.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.netcore.cs @@ -12073,13 +12073,11 @@ public static Vector128 Invoke(Vector128 x) // Handle signed integers specially, in order to throw if any attempt is made to // take the absolute value of the minimum value of the type, which doesn't have // a positive absolute value representation. - Vector128 negated = -x; - if (Vector128.Equals(x, negated) != Vector128.Zero) + Vector128 abs = Vector128.ConditionalSelect(Vector128.LessThan(x, Vector128.Zero), -x, x); + if (Vector128.LessThan(abs, Vector128.Zero) != Vector128.Zero) { ThrowNegateTwosCompOverflow(); } - - return Vector128.ConditionalSelect(Vector128.LessThan(x, Vector128.Zero), negated, x); } return Vector128.Abs(x); @@ -12097,13 +12095,11 @@ public static Vector256 Invoke(Vector256 x) // Handle signed integers specially, in order to throw if any attempt is made to // take the absolute value of the minimum value of the type, which doesn't have // a positive absolute value representation. - Vector256 negated = -x; - if (Vector256.Equals(x, negated) != Vector256.Zero) + Vector256 abs = Vector256.ConditionalSelect(Vector256.LessThan(x, Vector256.Zero), -x, x); + if (Vector256.LessThan(abs, Vector256.Zero) != Vector256.Zero) { ThrowNegateTwosCompOverflow(); } - - return Vector256.ConditionalSelect(Vector256.LessThan(x, Vector256.Zero), negated, x); } return Vector256.Abs(x); @@ -12121,13 +12117,11 @@ public static Vector512 Invoke(Vector512 x) // Handle signed integers specially, in order to throw if any attempt is made to // take the absolute value of the minimum value of the type, which doesn't have // a positive absolute value representation. - Vector512 negated = -x; - if (Vector512.Equals(x, negated) != Vector512.Zero) + Vector512 abs = Vector512.ConditionalSelect(Vector512.LessThan(x, Vector512.Zero), -x, x); + if (Vector512.LessThan(abs, Vector512.Zero) != Vector512.Zero) { ThrowNegateTwosCompOverflow(); } - - return Vector512.ConditionalSelect(Vector512.LessThan(x, Vector512.Zero), negated, x); } return Vector512.Abs(x);