diff gen/binops.cpp @ 1503:cc5fee7836dc

Made is and !is use the same numeric comparison as == and !=, fixes #328 Factored out common code from EqualExp and IdentityExp into DtoBinNumericEquals in binexp.cpp.
author Christian Kamm <kamm incasoftware de>
date Tue, 16 Jun 2009 23:00:27 +0200
parents ca2dfe98036c
children
line wrap: on
line diff
--- a/gen/binops.cpp	Tue Jun 16 19:31:10 2009 +0200
+++ b/gen/binops.cpp	Tue Jun 16 23:00:27 2009 +0200
@@ -5,6 +5,8 @@
 #include "gen/irstate.h"
 #include "gen/tollvm.h"
 #include "gen/dvalue.h"
+#include "gen/logger.h"
+#include "gen/complex.h"
 
 //////////////////////////////////////////////////////////////////////////////
 
@@ -65,3 +67,34 @@
         res = gIR->ir->CreateURem(l, r, "tmp");
     return new DImValue( targettype, res );
 }
+
+//////////////////////////////////////////////////////////////////////////////
+
+LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op)
+{
+    assert(op == TOKequal || op == TOKnotequal ||
+           op == TOKidentity || op == TOKnotidentity);
+    Type* t = lhs->getType()->toBasetype();
+    assert(t->isfloating());
+    Logger::println("numeric equality");
+
+    LLValue* lv = lhs->getRVal();
+    LLValue* rv = rhs->getRVal();
+    LLValue* res = 0;
+
+    if (t->iscomplex())
+    {
+        Logger::println("complex");
+        res = DtoComplexEquals(loc, op, lhs, rhs);
+    }
+    else if (t->isfloating())
+    {
+        Logger::println("floating");
+        res = (op == TOKidentity || op == TOKequal)
+        ?   gIR->ir->CreateFCmpOEQ(lv,rv,"tmp")
+        :   gIR->ir->CreateFCmpUNE(lv,rv,"tmp");
+    }
+    
+    assert(res);
+    return res;
+}