[CLN-list] A silly program
Richard B. Kreckel
kreckel at thep.physik.uni-mainz.de
Sun Nov 28 22:18:03 CET 2004
On Fri, 19 Nov 2004, Isidro [iso-8859-15] Cachadiña Gutiérrez wrote:
> I don't know if I'm wrong, but why are not defined elsewhere
>
> cln::operator-(const float , const cln::cl_R&)
>
> and some with double, etc. to compile this silly program.
>
> #include <cln/real.h>
> int main(int argc, char **argv)
> {
> cln::cl_F a,b;
> a=1;
> b=1.0-a;
> }
I've committed attached patch into CVS.
Please test.
Regards
-richy.
--
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>
-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cln/ChangeLog,v
retrieving revision 1.115
diff -a -u -r1.115 ChangeLog
--- ChangeLog 3 Nov 2004 22:34:45 -0000 1.115
+++ ChangeLog 28 Nov 2004 21:03:53 -0000
@@ -1,3 +1,14 @@
+2004-11-28 Richard B. Kreckel <kreckel at ginac.de>
+
+ 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 <icacha at unex.es>.
+
2004-11-03 Richard B. Kreckel <kreckel at ginac.de>
* Version 1.1.9 released.
Index: include/cln/dfloat.h
===================================================================
RCS file: /home/cvs/cln/include/cln/dfloat.h,v
retrieving revision 1.2
diff -a -u -r1.2 dfloat.h
--- include/cln/dfloat.h 6 May 2002 10:29:18 -0000 1.2
+++ include/cln/dfloat.h 28 Nov 2004 21:03:54 -0000
@@ -47,18 +47,38 @@
// 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 @@
#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
Index: include/cln/ffloat.h
===================================================================
RCS file: /home/cvs/cln/include/cln/ffloat.h,v
retrieving revision 1.2
diff -a -u -r1.2 ffloat.h
--- include/cln/ffloat.h 6 May 2002 10:29:18 -0000 1.2
+++ include/cln/ffloat.h 28 Nov 2004 21:03:54 -0000
@@ -47,18 +47,38 @@
// 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 @@
#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
Index: include/cln/float.h
===================================================================
RCS file: /home/cvs/cln/include/cln/float.h,v
retrieving revision 1.1
diff -a -u -r1.1 float.h
--- include/cln/float.h 28 Aug 2000 22:08:04 -0000 1.1
+++ include/cln/float.h 28 Nov 2004 21:03:56 -0000
@@ -172,6 +172,10 @@
{ 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 @@
{ 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 @@
{ 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 @@
{ 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 @@
{ 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 @@
{ 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 @@
{ 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 @@
{ 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 @@
#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
Index: include/cln/real.h
===================================================================
RCS file: /home/cvs/cln/include/cln/real.h,v
retrieving revision 1.2
diff -a -u -r1.2 real.h
--- include/cln/real.h 6 May 2002 10:29:18 -0000 1.2
+++ include/cln/real.h 28 Nov 2004 21:03:57 -0000
@@ -84,6 +84,10 @@
{ 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 @@
{ 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 @@
{ 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 @@
{ 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 @@
{ 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 @@
{ 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 @@
{ 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 @@
{ 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 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<cl_F&>(x = x + y); }
+inline cl_F& operator+= (cl_R& x, const double y) { return static_cast<cl_F&>(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 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<cl_F&>(x = x - y); }
+inline cl_F& operator-= (cl_R& x, const double y) { return static_cast<cl_F&>(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_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 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; }
More information about the CLN-list
mailing list