2003-05-12 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Mon, 12 May 2003 10:07:14 +0000 (10:07 -0000)
committerZoltan Varga <vargaz@gmail.com>
Mon, 12 May 2003 10:07:14 +0000 (10:07 -0000)
* mini-x86.c (mono_arch_output_basic_block): Handle negative zero
correctly.

* basic-float.cs: Added tests for negative zero.

svn path=/trunk/mono/; revision=14512

mono/mini/ChangeLog
mono/mini/basic-float.cs
mono/mini/mini-x86.c

index 6b5cec0497746409e0f137b46453e236fceaaeeb..b0d92322c5df1f0294ac76e1f2d2bb50054e6659 100644 (file)
@@ -1,3 +1,9 @@
+2003-05-12  Zoltan Varga  <vargaz@freemail.hu>
+
+       * mini-x86.c (mono_arch_output_basic_block): Handle negative zero
+       correctly.
+
+       * basic-float.cs: Added tests for negative zero.
 
 Sun May 11 14:56:27 CEST 2003 Paolo Molaro <lupus@ximian.com>
 
index 281175fd71a70719193b2b2de1cbe4a5a9f5467f..46fa8e42d67bdeda7d316ef6474019131f788c8d 100644 (file)
@@ -117,6 +117,23 @@ class Tests {
                return 4;
        }
 
+       static unsafe int test_2_negative_zero () {
+               int result = 0;
+               double d = -0.0;
+               float f = -0.0f;
+
+               byte *ptr = (byte*)&d;
+               if (ptr [7] == 0)
+                       return result;
+               result ++;
+
+               ptr = (byte*)&f;
+               if (ptr [3] == 0)
+                       return result;
+               result ++;
+
+               return result;
+       }
 
        static int test_15_float_cmp () {
                double a = 2.0;
index fb7e9852573447cf2d88fa484f6dd34a85496216..0390775396d34fda8c529cba22c14da0894d5520 100644 (file)
@@ -9,6 +9,7 @@
  */
 #include "mini.h"
 #include <string.h>
+#include <math.h>
 
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/debug-helpers.h>
@@ -2403,7 +2404,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                case OP_R8CONST: {
                        double d = *(double *)ins->inst_p0;
 
-                       if (d == 0.0) {
+                       if ((d == 0.0) && (signbit (d) == 0)) {
                                x86_fldz (code);
                        } else if (d == 1.0) {
                                x86_fld1 (code);
@@ -2416,7 +2417,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                case OP_R4CONST: {
                        float f = *(float *)ins->inst_p0;
 
-                       if (f == 0.0) {
+                       if ((f == 0.0) && (signbit (f) == 0)) {
                                x86_fldz (code);
                        } else if (f == 1.0) {
                                x86_fld1 (code);