Mercurial > projects > ddmd
view dmd/RealExp.d @ 45:ccbc1e0bb3f0
StringExp.equals implemented
int equals(Object o) -> bool equals(Object o)
author | korDen |
---|---|
date | Sat, 21 Aug 2010 07:26:20 +0400 |
parents | 10317f0c89a5 |
children | cab4c37afb89 |
line wrap: on
line source
module dmd.RealExp; import dmd.Expression; import dmd.backend.elem; import dmd.InterState; import dmd.Type; import dmd.OutBuffer; import dmd.Loc; import dmd.TOK; import dmd.Scope; import dmd.IRState; import dmd.Type; import dmd.HdrGenState; import dmd.Port; import dmd.TY; import dmd.backend.dt_t; import dmd.backend.Util; import dmd.backend.TYM; import dmd.backend.mTY; import dmd.Complex; class RealExp : Expression { real value; this(Loc loc, real value, Type type) { super(loc, TOK.TOKfloat64, RealExp.sizeof); //printf("RealExp.RealExp(%Lg)\n", value); this.value = value; this.type = type; } bool equals(Object o) { assert(false); } Expression semantic(Scope sc) { if (!type) type = Type.tfloat64; else type = type.semantic(loc, sc); return this; } Expression interpret(InterState* istate) { assert(false); } string toChars() { assert(false); } ulong toInteger() { assert(false); } ulong toUInteger() { assert(false); } real toReal() { return type.isreal() ? value : 0; } real toImaginary() { return type.isreal() ? 0 : value; } Complex!(real) toComplex() { return Complex!(real)(toReal(), toImaginary()); } Expression castTo(Scope sc, Type t) { Expression e = this; if (type != t) { if ((type.isreal() && t.isreal()) || (type.isimaginary() && t.isimaginary()) ) { e = copy(); e.type = t; } else e = Expression.castTo(sc, t); } return e; } int isConst() { return 1; } bool isBool(bool result) { assert(false); } void toCBuffer(OutBuffer buf, HdrGenState* hgs) { assert(false); } void toMangleBuffer(OutBuffer buf) { assert(false); } elem* toElem(IRState* irs) { eve c; tym_t ty; //printf("RealExp.toElem(%p) %s\n", this, toChars()); ///memset(&c, 0, sizeof(c)); ty = type.toBasetype().totym(); switch (tybasic(ty)) { case TYfloat: case TYifloat: c.Vfloat = value; if (Port.isSignallingNan(value)) { std.stdio.writeln("signalling float"); (cast(uint*)&c.Vfloat)[0] &= 0xFFBFFFFFL; } break; case TYdouble: case TYidouble: c.Vdouble = value; // unfortunately, this converts SNAN to QNAN if (Port.isSignallingNan(value)) { std.stdio.writeln("signalling double"); // Put SNAN back (cast(uint*)&c.Vdouble)[1] &= 0xFFF7FFFFL; } break; case TYldouble: case TYildouble: c.Vldouble = value; break; default: print(); ///type.print(); ///type.toBasetype().print(); writef("ty = %d, tym = %x\n", type.ty, ty); assert(0); } return el_const(ty, &c); } static private char[6] zeropad; dt_t** toDt(dt_t** pdt) { float fvalue; double dvalue; real evalue; //printf("RealExp.toDt(%Lg)\n", value); switch (type.toBasetype().ty) { case Tfloat32: case Timaginary32: fvalue = value; pdt = dtnbytes(pdt,4,cast(char*)&fvalue); break; case Tfloat64: case Timaginary64: dvalue = value; pdt = dtnbytes(pdt,8,cast(char*)&dvalue); break; case Tfloat80: case Timaginary80: evalue = value; pdt = dtnbytes(pdt,REALSIZE - REALPAD,cast(char*)&evalue); pdt = dtnbytes(pdt,REALPAD,zeropad.ptr); assert(REALPAD <= zeropad.sizeof); break; default: writef("%s\n", toChars()); ///type.print(); assert(0); break; } return pdt; } }