From 4315b52bf6b866ad56631ee3a252b3327d8a174c Mon Sep 17 00:00:00 2001 From: skyoxZ Date: Tue, 13 Jun 2023 04:49:10 +0800 Subject: [PATCH] Fix Double.NegativeZero (#87364) --- src/libraries/System.Runtime/ref/System.Runtime.cs | 4 ++-- src/libraries/System.Runtime/tests/System/DoubleTests.cs | 6 ++++++ src/libraries/System.Runtime/tests/System/SingleTests.cs | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index f961d94d5e1..54e75c953d3 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -2190,7 +2190,7 @@ namespace System public const double MinValue = -1.7976931348623157E+308; public const double NaN = 0.0 / 0.0; public const double NegativeInfinity = -1.0 / 0.0; - public const double NegativeZero = -0; + public const double NegativeZero = -0.0; public const double Pi = 3.141592653589793; public const double PositiveInfinity = 1.0 / 0.0; public const double Tau = 6.283185307179586; @@ -4879,7 +4879,7 @@ namespace System public const float MinValue = -3.4028235E+38f; public const float NaN = 0.0f / 0.0f; public const float NegativeInfinity = -1.0f / 0.0f; - public const float NegativeZero = -0f; + public const float NegativeZero = -0.0f; public const float Pi = 3.1415927f; public const float PositiveInfinity = 1.0f / 0.0f; public const float Tau = 6.2831855f; diff --git a/src/libraries/System.Runtime/tests/System/DoubleTests.cs b/src/libraries/System.Runtime/tests/System/DoubleTests.cs index b2a93df11b4..edb7155191f 100644 --- a/src/libraries/System.Runtime/tests/System/DoubleTests.cs +++ b/src/libraries/System.Runtime/tests/System/DoubleTests.cs @@ -324,6 +324,12 @@ namespace System.Tests Assert.Equal(0xFFF00000_00000000u, BitConverter.DoubleToUInt64Bits(double.NegativeInfinity)); } + [Fact] + public static void NegativeZero() + { + Assert.Equal(0x80000000_00000000u, BitConverter.DoubleToUInt64Bits(double.NegativeZero)); + } + public static IEnumerable Parse_Valid_TestData() { NumberStyles defaultStyle = NumberStyles.Float | NumberStyles.AllowThousands; diff --git a/src/libraries/System.Runtime/tests/System/SingleTests.cs b/src/libraries/System.Runtime/tests/System/SingleTests.cs index 07414d87596..49eaecf1592 100644 --- a/src/libraries/System.Runtime/tests/System/SingleTests.cs +++ b/src/libraries/System.Runtime/tests/System/SingleTests.cs @@ -321,6 +321,12 @@ namespace System.Tests Assert.Equal(0xFF800000u, BitConverter.SingleToUInt32Bits(float.NegativeInfinity)); } + [Fact] + public static void NegativeZero() + { + Assert.Equal(0x80000000u, BitConverter.SingleToUInt32Bits(float.NegativeZero)); + } + public static IEnumerable Parse_Valid_TestData() { NumberStyles defaultStyle = NumberStyles.Float | NumberStyles.AllowThousands; -- 2.34.1