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.
This commit is contained in:
Christian Kamm
2009-06-16 23:00:27 +02:00
parent 4158fb474a
commit 7dbe9baa37
4 changed files with 60 additions and 46 deletions

View File

@@ -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 @@ DValue* DtoBinRem(Type* targettype, DValue* lhs, DValue* rhs)
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;
}