diff --git a/ChangeLog b/ChangeLog index f2d33f5..424d644 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-11-28 Richard B. Kreckel + + Disambiguate binary operators of CLN types with float/double + * include/cln/dfloat.h: Add binary operator overloads for arguments of + type double. + * include/cln/ffloat.h: Likewise, for arguments of type float. + * include/cln/float.h: Likewise, both for arguments of types double and + float. + * include/cln/real.h: Likewise. + Reported by Isidro Cachadiña Gutiérrez . + 2004-11-03 Richard B. Kreckel * Version 1.1.9 released. diff --git a/include/cln/dfloat.h b/include/cln/dfloat.h index b70cb88..fde8a80 100644 --- a/include/cln/dfloat.h +++ b/include/cln/dfloat.h @@ -47,18 +47,38 @@ extern cl_boolean plusp (const cl_DF& x); // Liefert zu zwei Double-Float x und y : (+ x y), ein DF. extern const cl_DF operator+ (const cl_DF& x, const cl_DF& y); +// The C++ compiler may hesitate to do these conversions of its own: +inline const cl_DF operator+ (const cl_DF& x, const double y) + { return x + cl_DF(y); } +inline const cl_DF operator+ (const double x, const cl_DF& y) + { return cl_DF(x) + y; } // Liefert zu zwei Double-Float x und y : (- x y), ein DF. extern const cl_DF operator- (const cl_DF& x, const cl_DF& y); +// The C++ compiler may hesitate to do these conversions of its own: +inline const cl_DF operator- (const cl_DF& x, const double y) + { return x - cl_DF(y); } +inline const cl_DF operator- (const double x, const cl_DF& y) + { return cl_DF(x) - y; } // Liefert zu zwei Double-Float x und y : (* x y), ein DF. extern const cl_DF operator* (const cl_DF& x, const cl_DF& y); +// The C++ compiler may hesitate to do these conversions of its own: +inline const cl_DF operator* (const cl_DF& x, const double y) + { return x * cl_DF(y); } +inline const cl_DF operator* (const double x, const cl_DF& y) + { return cl_DF(x) * y; } // Liefert zu einem Double-Float x : (* x x), ein DF. inline const cl_DF square (const cl_DF& x) { return x*x; } // Liefert zu zwei Double-Float x und y : (/ x y), ein DF. extern const cl_DF operator/ (const cl_DF& x, const cl_DF& y); +// The C++ compiler may hesitate to do these conversions of its own: +inline const cl_DF operator/ (const cl_DF& x, const double y) + { return x / cl_DF(y); } +inline const cl_DF operator/ (const double x, const cl_DF& y) + { return cl_DF(x) / y; } // Liefert zu einem Double-Float x>=0 : (sqrt x), ein DF. extern const cl_DF sqrt (const cl_DF& x); @@ -276,13 +296,17 @@ extern double double_approx (const cl_DF& x); #ifdef WANT_OBFUSCATING_OPERATORS // This could be optimized to use in-place operations. inline cl_DF& operator+= (cl_DF& x, const cl_DF& y) { return x = x + y; } +inline cl_DF& operator+= (cl_DF& x, const double y) { return x = x + y; } inline cl_DF& operator++ /* prefix */ (cl_DF& x) { return x = plus1(x); } inline void operator++ /* postfix */ (cl_DF& x, int dummy) { (void)dummy; x = plus1(x); } inline cl_DF& operator-= (cl_DF& x, const cl_DF& y) { return x = x - y; } +inline cl_DF& operator-= (cl_DF& x, const double y) { return x = x - y; } inline cl_DF& operator-- /* prefix */ (cl_DF& x) { return x = minus1(x); } inline void operator-- /* postfix */ (cl_DF& x, int dummy) { (void)dummy; x = minus1(x); } inline cl_DF& operator*= (cl_DF& x, const cl_DF& y) { return x = x * y; } +inline cl_DF& operator*= (cl_DF& x, const double y) { return x = x * y; } inline cl_DF& operator/= (cl_DF& x, const cl_DF& y) { return x = x / y; } +inline cl_DF& operator/= (cl_DF& x, const double y) { return x = x / y; } #endif diff --git a/include/cln/ffloat.h b/include/cln/ffloat.h index a107a5e..0644108 100644 --- a/include/cln/ffloat.h +++ b/include/cln/ffloat.h @@ -47,18 +47,38 @@ extern cl_boolean plusp (const cl_FF& x); // Liefert zu zwei Single-Float x und y : (+ x y), ein FF. extern const cl_FF operator+ (const cl_FF& x, const cl_FF& y); +// The C++ compiler may hesitate to do these conversions of its own: +inline const cl_FF operator+ (const cl_FF& x, const float y) + { return x + cl_FF(y); } +inline const cl_FF operator+ (const float x, const cl_FF& y) + { return cl_FF(x) + y; } // Liefert zu zwei Single-Float x und y : (- x y), ein FF. extern const cl_FF operator- (const cl_FF& x, const cl_FF& y); +// The C++ compiler may hesitate to do these conversions of its own: +inline const cl_FF operator- (const cl_FF& x, const float y) + { return x - cl_FF(y); } +inline const cl_FF operator- (const float x, const cl_FF& y) + { return cl_FF(x) - y; } // Liefert zu zwei Single-Float x und y : (* x y), ein FF. extern const cl_FF operator* (const cl_FF& x, const cl_FF& y); +// The C++ compiler may hesitate to do these conversions of its own: +inline const cl_FF operator* (const cl_FF& x, const float y) + { return x * cl_FF(y); } +inline const cl_FF operator* (const float x, const cl_FF& y) + { return cl_FF(x) * y; } // Liefert zu einem Single-Float x : (* x x), ein FF. inline const cl_FF square (const cl_FF& x) { return x*x; } // Liefert zu zwei Single-Float x und y : (/ x y), ein FF. extern const cl_FF operator/ (const cl_FF& x, const cl_FF& y); +// The C++ compiler may hesitate to do these conversions of its own: +inline const cl_FF operator/ (const cl_FF& x, const float y) + { return x / cl_FF(y); } +inline const cl_FF operator/ (const float x, const cl_FF& y) + { return cl_FF(x) / y; } // Liefert zu einem Single-Float x>=0 : (sqrt x), ein FF. extern const cl_FF sqrt (const cl_FF& x); @@ -276,13 +296,17 @@ extern double double_approx (const cl_FF& x); #ifdef WANT_OBFUSCATING_OPERATORS // This could be optimized to use in-place operations. inline cl_FF& operator+= (cl_FF& x, const cl_FF& y) { return x = x + y; } +inline cl_FF& operator+= (cl_FF& x, const float y) { return x = x + y; } inline cl_FF& operator++ /* prefix */ (cl_FF& x) { return x = plus1(x); } inline void operator++ /* postfix */ (cl_FF& x, int dummy) { (void)dummy; x = plus1(x); } inline cl_FF& operator-= (cl_FF& x, const cl_FF& y) { return x = x - y; } +inline cl_FF& operator-= (cl_FF& x, const float y) { return x = x - y; } inline cl_FF& operator-- /* prefix */ (cl_FF& x) { return x = minus1(x); } inline void operator-- /* postfix */ (cl_FF& x, int dummy) { (void)dummy; x = minus1(x); } inline cl_FF& operator*= (cl_FF& x, const cl_FF& y) { return x = x * y; } +inline cl_FF& operator*= (cl_FF& x, const float y) { return x = x * y; } inline cl_FF& operator/= (cl_FF& x, const cl_FF& y) { return x = x / y; } +inline cl_FF& operator/= (cl_FF& x, const float y) { return x = x / y; } #endif diff --git a/include/cln/float.h b/include/cln/float.h index 4c004a4..471cb36 100644 --- a/include/cln/float.h +++ b/include/cln/float.h @@ -172,6 +172,10 @@ inline const cl_F operator+ (const long x, const cl_F& y) { return cl_I(x) + y; } inline const cl_F operator+ (const unsigned long x, const cl_F& y) { return cl_I(x) + y; } +inline const cl_F operator+ (const float x, const cl_F& y) + { return cl_F(x) + y; } +inline const cl_F operator+ (const double x, const cl_F& y) + { return cl_F(x) + y; } inline const cl_F operator+ (const cl_F& x, const int y) { return x + cl_I(y); } inline const cl_F operator+ (const cl_F& x, const unsigned int y) @@ -180,6 +184,10 @@ inline const cl_F operator+ (const cl_F& x, const long y) { return x + cl_I(y); } inline const cl_F operator+ (const cl_F& x, const unsigned long y) { return x + cl_I(y); } +inline const cl_F operator+ (const cl_F& x, const float y) + { return x + cl_F(y); } +inline const cl_F operator+ (const cl_F& x, const double y) + { return x + cl_F(y); } // Liefert (- x y), wo x und y Floats sind. extern const cl_F operator- (const cl_F& x, const cl_F& y); @@ -201,6 +209,10 @@ inline const cl_F operator- (const long x, const cl_F& y) { return cl_I(x) - y; } inline const cl_F operator- (const unsigned long x, const cl_F& y) { return cl_I(x) - y; } +inline const cl_F operator- (const float x, const cl_F& y) + { return cl_F(x) - y; } +inline const cl_F operator- (const double x, const cl_F& y) + { return cl_F(x) - y; } inline const cl_F operator- (const cl_F& x, const int y) { return x - cl_I(y); } inline const cl_F operator- (const cl_F& x, const unsigned int y) @@ -209,6 +221,10 @@ inline const cl_F operator- (const cl_F& x, const long y) { return x - cl_I(y); } inline const cl_F operator- (const cl_F& x, const unsigned long y) { return x - cl_I(y); } +inline const cl_F operator- (const cl_F& x, const float y) + { return x - cl_F(y); } +inline const cl_F operator- (const cl_F& x, const double y) + { return x - cl_F(y); } // Liefert (* x y), wo x und y Floats sind. extern const cl_F operator* (const cl_F& x, const cl_F& y); @@ -242,6 +258,10 @@ inline const cl_R operator* (const long x, const cl_F& y) { return cl_I(x) * y; } inline const cl_R operator* (const unsigned long x, const cl_F& y) { return cl_I(x) * y; } +inline const cl_F operator* (const float x, const cl_F& y) + { return cl_F(x) * y; } +inline const cl_F operator* (const double x, const cl_F& y) + { return cl_F(x) * y; } inline const cl_R operator* (const cl_F& x, const int y) { return x * cl_I(y); } inline const cl_R operator* (const cl_F& x, const unsigned int y) @@ -250,6 +270,10 @@ inline const cl_R operator* (const cl_F& x, const long y) { return x * cl_I(y); } inline const cl_R operator* (const cl_F& x, const unsigned long y) { return x * cl_I(y); } +inline const cl_F operator* (const cl_F& x, const float y) + { return x * cl_F(y); } +inline const cl_F operator* (const cl_F& x, const double y) + { return x * cl_F(y); } // Liefert (* x x), wo x ein Float ist. extern const cl_F square (const cl_F& x); @@ -270,6 +294,10 @@ inline const cl_F operator/ (const cl_F& x, const long y) { return x / cl_I(y); } inline const cl_F operator/ (const cl_F& x, const unsigned long y) { return x / cl_I(y); } +inline const cl_F operator/ (const cl_F& x, const float y) + { return x / cl_F(y); } +inline const cl_F operator/ (const cl_F& x, const double y) + { return x / cl_F(y); } inline const cl_R operator/ (const int x, const cl_F& y) { return cl_I(x) / y; } inline const cl_R operator/ (const unsigned int x, const cl_F& y) @@ -278,6 +306,10 @@ inline const cl_R operator/ (const long x, const cl_F& y) { return cl_I(x) / y; } inline const cl_R operator/ (const unsigned long x, const cl_F& y) { return cl_I(x) / y; } +inline const cl_F operator/ (const float x, const cl_F& y) + { return cl_F(x) / y; } +inline const cl_F operator/ (const double x, const cl_F& y) + { return cl_F(x) / y; } // Liefert (abs x), wo x ein Float ist. extern const cl_F abs (const cl_F& x); @@ -636,13 +668,21 @@ inline const cl_F random_F (const cl_F& n) #ifdef WANT_OBFUSCATING_OPERATORS // This could be optimized to use in-place operations. inline cl_F& operator+= (cl_F& x, const cl_F& y) { return x = x + y; } +inline cl_F& operator+= (cl_F& x, const float y) { return x = x + y; } +inline cl_F& operator+= (cl_F& x, const double y) { return x = x + y; } inline cl_F& operator++ /* prefix */ (cl_F& x) { return x = plus1(x); } inline void operator++ /* postfix */ (cl_F& x, int dummy) { (void)dummy; x = plus1(x); } inline cl_F& operator-= (cl_F& x, const cl_F& y) { return x = x - y; } +inline cl_F& operator-= (cl_F& x, const float y) { return x = x - y; } +inline cl_F& operator-= (cl_F& x, const double y) { return x = x - y; } inline cl_F& operator-- /* prefix */ (cl_F& x) { return x = minus1(x); } inline void operator-- /* postfix */ (cl_F& x, int dummy) { (void)dummy; x = minus1(x); } inline cl_F& operator*= (cl_F& x, const cl_F& y) { return x = x * y; } +inline cl_F& operator*= (cl_F& x, const float y) { return x = x * y; } +inline cl_F& operator*= (cl_F& x, const double y) { return x = x * y; } inline cl_F& operator/= (cl_F& x, const cl_F& y) { return x = x / y; } +inline cl_F& operator/= (cl_F& x, const float y) { return x = x / y; } +inline cl_F& operator/= (cl_F& x, const double y) { return x = x / y; } #endif diff --git a/include/cln/real.h b/include/cln/real.h index f29465f..5c2a2bd 100644 --- a/include/cln/real.h +++ b/include/cln/real.h @@ -84,6 +84,10 @@ inline const cl_R operator+ (const long x, const cl_R& y) { return cl_I(x) + y; } inline const cl_R operator+ (const unsigned long x, const cl_R& y) { return cl_I(x) + y; } +inline const cl_F operator+ (const float x, const cl_R& y) + { return The(cl_F)(cl_R(x) + y); } +inline const cl_F operator+ (const double x, const cl_R& y) + { return The(cl_F)(cl_R(x) + y); } inline const cl_R operator+ (const cl_R& x, const int y) { return x + cl_I(y); } inline const cl_R operator+ (const cl_R& x, const unsigned int y) @@ -92,6 +96,10 @@ inline const cl_R operator+ (const cl_R& x, const long y) { return x + cl_I(y); } inline const cl_R operator+ (const cl_R& x, const unsigned long y) { return x + cl_I(y); } +inline const cl_F operator+ (const cl_R& x, const float y) + { return The(cl_F)(x + cl_R(y)); } +inline const cl_F operator+ (const cl_R& x, const double y) + { return The(cl_F)(x + cl_R(y)); } // Liefert (- x y), wo x und y reelle Zahlen sind. extern const cl_R operator- (const cl_R& x, const cl_R& y); @@ -109,6 +117,10 @@ inline const cl_R operator- (const long x, const cl_R& y) { return cl_I(x) - y; } inline const cl_R operator- (const unsigned long x, const cl_R& y) { return cl_I(x) - y; } +inline const cl_F operator- (const float x, const cl_R& y) + { return The(cl_F)(cl_R(x) - y); } +inline const cl_F operator- (const double x, const cl_R& y) + { return The(cl_F)(cl_R(x) - y); } inline const cl_R operator- (const cl_R& x, const int y) { return x - cl_I(y); } inline const cl_R operator- (const cl_R& x, const unsigned int y) @@ -117,6 +129,10 @@ inline const cl_R operator- (const cl_R& x, const long y) { return x - cl_I(y); } inline const cl_R operator- (const cl_R& x, const unsigned long y) { return x - cl_I(y); } +inline const cl_F operator- (const cl_R& x, const float y) + { return The(cl_F)(x - cl_R(y)); } +inline const cl_F operator- (const cl_R& x, const double y) + { return The(cl_F)(x - cl_R(y)); } // Liefert (* x y), wo x und y reelle Zahlen sind. extern const cl_R operator* (const cl_R& x, const cl_R& y); @@ -129,6 +145,10 @@ inline const cl_R operator* (const long x, const cl_R& y) { return cl_I(x) * y; } inline const cl_R operator* (const unsigned long x, const cl_R& y) { return cl_I(x) * y; } +inline const cl_R operator* (const float x, const cl_R& y) + { return cl_R(x) * y; } +inline const cl_R operator* (const double x, const cl_R& y) + { return cl_R(x) * y; } inline const cl_R operator* (const cl_R& x, const int y) { return x * cl_I(y); } inline const cl_R operator* (const cl_R& x, const unsigned int y) @@ -137,13 +157,17 @@ inline const cl_R operator* (const cl_R& x, const long y) { return x * cl_I(y); } inline const cl_R operator* (const cl_R& x, const unsigned long y) { return x * cl_I(y); } +inline const cl_R operator* (const cl_R& x, const float y) + { return x * cl_R(y); } +inline const cl_R operator* (const cl_R& x, const double y) + { return x * cl_R(y); } // Liefert (* x x), wo x eine reelle Zahl ist. extern const cl_R square (const cl_R& x); // Liefert (/ x y), wo x und y reelle Zahlen sind. extern const cl_R operator/ (const cl_R& x, const cl_R& y); -// Spezialfall: x oder y Float -> Ergebnis Float +// Spezialfall: x Float -> Ergebnis Float inline const cl_F operator/ (const cl_F& x, const cl_R& y) { return The(cl_F)(The(cl_R)(x) / y); } // Dem C++-Compiler muß man auch das Folgende sagen (wg. `int / cl_F' u.ä.): @@ -155,6 +179,10 @@ inline const cl_R operator/ (const long x, const cl_R& y) { return cl_I(x) / y; } inline const cl_R operator/ (const unsigned long x, const cl_R& y) { return cl_I(x) / y; } +inline const cl_F operator/ (const float x, const cl_R& y) + { return The(cl_F)(cl_R(x) / y); } +inline const cl_F operator/ (const double x, const cl_R& y) + { return The(cl_F)(cl_R(x) / y); } inline const cl_R operator/ (const cl_R& x, const int y) { return x / cl_I(y); } inline const cl_R operator/ (const cl_R& x, const unsigned int y) @@ -163,6 +191,10 @@ inline const cl_R operator/ (const cl_R& x, const long y) { return x / cl_I(y); } inline const cl_R operator/ (const cl_R& x, const unsigned long y) { return x / cl_I(y); } +inline const cl_R operator/ (const cl_R& x, const float y) + { return x / cl_R(y); } +inline const cl_R operator/ (const cl_R& x, const double y) + { return x / cl_R(y); } // Liefert (abs x), wo x eine reelle Zahl ist. extern const cl_R abs (const cl_R& x); @@ -455,6 +487,8 @@ inline cl_R& operator+= (cl_R& x, const int y) { return x = x + y; } inline cl_R& operator+= (cl_R& x, const unsigned int y) { return x = x + y; } inline cl_R& operator+= (cl_R& x, const long y) { return x = x + y; } inline cl_R& operator+= (cl_R& x, const unsigned long y) { return x = x + y; } +inline cl_F& operator+= (cl_R& x, const float y) { return static_cast(x = x + y); } +inline cl_F& operator+= (cl_R& x, const double y) { return static_cast(x = x + y); } inline cl_F& operator+= (cl_F& x, const int y) { return x = x + y; } inline cl_F& operator+= (cl_F& x, const unsigned int y) { return x = x + y; } inline cl_F& operator+= (cl_F& x, const long y) { return x = x + y; } @@ -469,6 +503,8 @@ inline cl_R& operator-= (cl_R& x, const int y) { return x = x - y; } inline cl_R& operator-= (cl_R& x, const unsigned int y) { return x = x - y; } inline cl_R& operator-= (cl_R& x, const long y) { return x = x - y; } inline cl_R& operator-= (cl_R& x, const unsigned long y) { return x = x - y; } +inline cl_F& operator-= (cl_R& x, const float y) { return static_cast(x = x - y); } +inline cl_F& operator-= (cl_R& x, const double y) { return static_cast(x = x - y); } inline cl_F& operator-= (cl_F& x, const int y) { return x = x - y; } inline cl_F& operator-= (cl_F& x, const unsigned int y) { return x = x - y; } inline cl_F& operator-= (cl_F& x, const long y) { return x = x - y; } @@ -476,6 +512,12 @@ inline cl_F& operator-= (cl_F& x, const unsigned long y) { return x = x - y; } inline cl_R& operator-- /* prefix */ (cl_R& x) { return x = minus1(x); } inline void operator-- /* postfix */ (cl_R& x, int dummy) { (void)dummy; x = minus1(x); } inline cl_R& operator*= (cl_R& x, const cl_R& y) { return x = x * y; } +inline cl_R& operator*= (cl_R& x, const int y) { return x = x * y; } +inline cl_R& operator*= (cl_R& x, const unsigned int y) { return x = x * y; } +inline cl_R& operator*= (cl_R& x, const long y) { return x = x * y; } +inline cl_R& operator*= (cl_R& x, const unsigned long y) { return x = x * y; } +inline cl_R& operator*= (cl_R& x, const float y) { return x = x * y; } +inline cl_R& operator*= (cl_R& x, const double y) { return x = x * y; } inline cl_R& operator/= (cl_R& x, const cl_R& y) { return x = x / y; } inline cl_F& operator/= (cl_F& x, const cl_R& y) { return x = x / y; } inline cl_F& operator/= (cl_F& x, const cl_RA& y) { return x = x / y; } @@ -484,6 +526,8 @@ inline cl_R& operator/= (cl_R& x, const int y) { return x = x / y; } inline cl_R& operator/= (cl_R& x, const unsigned int y) { return x = x / y; } inline cl_R& operator/= (cl_R& x, const long y) { return x = x / y; } inline cl_R& operator/= (cl_R& x, const unsigned long y) { return x = x / y; } +inline cl_R& operator/= (cl_R& x, const float y) { return x = x / y; } +inline cl_R& operator/= (cl_R& x, const double y) { return x = x / y; } inline cl_F& operator/= (cl_F& x, const int y) { return x = x / y; } inline cl_F& operator/= (cl_F& x, const unsigned int y) { return x = x / y; } inline cl_F& operator/= (cl_F& x, const long y) { return x = x / y; }