diff --git a/uppsrc/Core/Complex.h b/uppsrc/Core/Complex.h new file mode 100644 index 000000000..4d7dd9356 --- /dev/null +++ b/uppsrc/Core/Complex.h @@ -0,0 +1,38 @@ +const dword COMPLEX_V = 20; + +struct Complex : std::complex +{ + typedef std::complex C; + + Complex() {} + Complex(double r) : C(r) {} + Complex(double r, double i) : C(r,i) {} + Complex(const C& c) : C(c) {} + + Complex(const Nuller&) : C(DOUBLE_NULL) {} + operator Value() const { return RichValue(*this); } + Complex(const Value& v) : C(RichValue::Extract(v)) {} + + bool operator==(const Complex& c) const { return (const C&)(*this) == (const C&)c; } + bool operator!=(const Complex& c) const { return (const C&)(*this) != (const C&)c; } +}; + +template<> inline bool IsNull(const Complex& r) { return r.real() < DOUBLE_NULL_LIM || r.imag() < DOUBLE_NULL_LIM; } +template<> inline unsigned GetHashValue(const Complex& x) { return CombineHash(x.real(), x.imag()); } +template<> inline String AsString(const Complex& x) { return String().Cat() << "(" << x.real() << "," << x.imag() << ")"; } + +template<> inline Stream& operator%(Stream& s, Complex& c) +{ + double r,i; + if(s.IsStoring()) { r = c.real(); i = c.imag(); } + s % r % i; + if(s.IsLoading()) { c = Complex(r,i); } + return s; +} + +template<> inline dword ValueTypeNo(const Complex*) { return COMPLEX_V; } + +inline const Complex& Nvl(const Complex& a, const Complex& b) { return IsNull(a) ? b : a; } + +VALUE_COMPARE(Complex) +NTL_MOVEABLE(Complex) diff --git a/uppsrc/Core/Core.h b/uppsrc/Core/Core.h index 230ef888c..7889f80e2 100644 --- a/uppsrc/Core/Core.h +++ b/uppsrc/Core/Core.h @@ -168,6 +168,7 @@ #include #include +#include // fix MSC8 beta problem.... #ifdef COMPILER_MSC @@ -240,6 +241,7 @@ NAMESPACE_UPP #include "Value.h" #include "Gtypes.h" #include "Color.h" +#include "Complex.h" #include "Uuid.h" #include "Ptr.h" diff --git a/uppsrc/Core/Core.upp b/uppsrc/Core/Core.upp index b023f79f9..f07b924c5 100644 --- a/uppsrc/Core/Core.upp +++ b/uppsrc/Core/Core.upp @@ -99,6 +99,7 @@ file TimeDate.cpp optimize_speed, Value.h, Value.cpp optimize_speed, + Complex.h, Format.h, Format.cpp optimize_speed, Convert.h, diff --git a/uppsrc/Core/Value.cpp b/uppsrc/Core/Value.cpp index 314d658fc..a8f776753 100644 --- a/uppsrc/Core/Value.cpp +++ b/uppsrc/Core/Value.cpp @@ -152,6 +152,7 @@ static void sRegisterStd() RichValue::Register(); RichValue::Register(); RichValue