diff --git a/dmd/complex_t.h b/dmd/complex_t.h index a1b4f4ed..fa39271e 100644 --- a/dmd/complex_t.h +++ b/dmd/complex_t.h @@ -16,12 +16,14 @@ struct complex_t { - long double re; - long double im; + longdouble re; + longdouble im; complex_t() { this->re = 0; this->im = 0; } - complex_t(long double re) { this->re = re; this->im = 0; } - complex_t(long double re, long double im) { this->re = re; this->im = im; } + complex_t(longdouble re) { this->re = re; this->im = 0; } + complex_t(double re) { this->re = re; this->im = 0; } + complex_t(longdouble re, longdouble im) { this->re = re; this->im = im; } + complex_t(double re, double im) { this->re = re; this->im = im; } complex_t operator + (complex_t y) { complex_t r; r.re = re + y.re; r.im = im + y.im; return r; } complex_t operator - (complex_t y) { complex_t r; r.re = re - y.re; r.im = im - y.im; return r; } @@ -30,9 +32,9 @@ struct complex_t complex_t operator / (complex_t y) { - long double abs_y_re = y.re < 0 ? -y.re : y.re; - long double abs_y_im = y.im < 0 ? -y.im : y.im; - long double r, den; + longdouble abs_y_re = y.re < 0 ? -y.re : y.re; + longdouble abs_y_im = y.im < 0 ? -y.im : y.im; + longdouble r, den; if (abs_y_re < abs_y_im) { @@ -56,17 +58,17 @@ struct complex_t int operator != (complex_t y) { return re != y.re || im != y.im; } }; -inline complex_t operator * (long double x, complex_t y) { return complex_t(x) * y; } -inline complex_t operator * (complex_t x, long double y) { return x * complex_t(y); } -inline complex_t operator / (complex_t x, long double y) { return x / complex_t(y); } +inline complex_t operator * (longdouble x, complex_t y) { return complex_t(x) * y; } +inline complex_t operator * (complex_t x, longdouble y) { return x * complex_t(y); } +inline complex_t operator / (complex_t x, longdouble y) { return x / complex_t(y); } -inline long double creall(complex_t x) +inline longdouble creall(complex_t x) { return x.re; } -inline long double cimagl(complex_t x) +inline longdouble cimagl(complex_t x) { return x.im; } diff --git a/dmd/expression.c b/dmd/expression.c index ab6e036e..bf618058 100644 --- a/dmd/expression.c +++ b/dmd/expression.c @@ -1074,13 +1074,13 @@ uinteger_t Expression::toUInteger() real_t Expression::toReal() { error("Floating point constant expression expected instead of %s", toChars()); - return 0; + return ldouble(0); } real_t Expression::toImaginary() { error("Floating point constant expression expected instead of %s", toChars()); - return 0; + return ldouble(0); } complex_t Expression::toComplex() @@ -1089,7 +1089,7 @@ complex_t Expression::toComplex() #ifdef IN_GCC return complex_t(real_t(0)); // %% nicer #else - return 0; + return 0.0; #endif } @@ -1473,14 +1473,14 @@ real_t IntegerExp::toReal() toInteger(); t = type->toBasetype(); if (t->ty == Tuns64) - return (real_t)(d_uns64)value; + return ldouble((d_uns64)value); else - return (real_t)(d_int64)value; + return ldouble((d_int64)value); } real_t IntegerExp::toImaginary() { - return (real_t) 0; + return ldouble(0); } complex_t IntegerExp::toComplex() @@ -1722,12 +1722,12 @@ uinteger_t RealExp::toUInteger() real_t RealExp::toReal() { - return type->isreal() ? value : 0; + return type->isreal() ? value : ldouble(0); } real_t RealExp::toImaginary() { - return type->isreal() ? 0 : value; + return type->isreal() ? ldouble(0) : value; } complex_t RealExp::toComplex() @@ -9251,7 +9251,7 @@ Expression *DivAssignExp::semantic(Scope *sc) if (t1->isreal()) { // x/iv = i(-x/v) // Therefore, the result is 0 - e2 = new CommaExp(loc, e2, new RealExp(loc, 0, t1)); + e2 = new CommaExp(loc, e2, new RealExp(loc, ldouble(0), t1)); e2->type = t1; e = new AssignExp(loc, e1, e2); e->type = t1; diff --git a/dmd/mars.h b/dmd/mars.h index 4110ccd2..1873efd9 100644 --- a/dmd/mars.h +++ b/dmd/mars.h @@ -371,8 +371,10 @@ extern Global global; */ #define WINDOWS_SEH (_WIN32 && __DMC__) +#include "longdouble.h" #ifdef __DMC__ + #include typedef _Complex long double complex_t; #else #ifndef IN_GCC @@ -403,7 +405,7 @@ typedef uint64_t d_uns64; typedef float d_float32; typedef double d_float64; -typedef long double d_float80; +typedef longdouble d_float80; typedef d_uns8 d_char; typedef d_uns16 d_wchar; @@ -412,7 +414,7 @@ typedef d_uns32 d_dchar; #ifdef IN_GCC #include "d-gcc-real.h" #else -typedef long double real_t; +typedef longdouble real_t; #endif // Modify OutBuffer::writewchar to write the correct size of wchar diff --git a/dmd/mtype.c b/dmd/mtype.c index 729a3fd5..5130dec6 100644 --- a/dmd/mtype.c +++ b/dmd/mtype.c @@ -1451,7 +1451,7 @@ Expression *TypeBasic::dotExp(Scope *sc, Expression *e, Identifier *ident) case Timaginary64: t = tfloat64; goto L2; case Timaginary80: t = tfloat80; goto L2; L2: - e = new RealExp(e->loc, 0.0, t); + e = new RealExp(e->loc, ldouble(0.0), t); break; default: @@ -1481,7 +1481,7 @@ Expression *TypeBasic::dotExp(Scope *sc, Expression *e, Identifier *ident) case Tfloat32: case Tfloat64: case Tfloat80: - e = new RealExp(e->loc, 0.0, this); + e = new RealExp(e->loc, ldouble(0.0), this); break; default: