Fix Double.NegativeZero (#87364)
authorskyoxZ <skyoxZ@qq.com>
Mon, 12 Jun 2023 20:49:10 +0000 (04:49 +0800)
committerGitHub <noreply@github.com>
Mon, 12 Jun 2023 20:49:10 +0000 (13:49 -0700)
src/libraries/System.Runtime/ref/System.Runtime.cs
src/libraries/System.Runtime/tests/System/DoubleTests.cs
src/libraries/System.Runtime/tests/System/SingleTests.cs

index f961d94d5e14549ec4ac1563f662460badd73892..54e75c953d3ad0cc4ff31ba21f23cc76d1cb3046 100644 (file)
@@ -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;
index b2a93df11b4804c199b6bd5ec3a17b278d3bc6b1..edb7155191fdd40f0b72dc9a0efaf847ddc8fc3b 100644 (file)
@@ -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<object[]> Parse_Valid_TestData()
         {
             NumberStyles defaultStyle = NumberStyles.Float | NumberStyles.AllowThousands;
index 07414d8759668fba8f86ec84ee908ef59c3905e3..49eaecf159285b9826778cf7d60d1a5037c2feac 100644 (file)
@@ -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<object[]> Parse_Valid_TestData()
         {
             NumberStyles defaultStyle = NumberStyles.Float | NumberStyles.AllowThousands;