Index: src/libcfa/rational
===================================================================
--- src/libcfa/rational	(revision f621a148a747ee2f6841e0a8767c6a3c5fdc51a1)
+++ src/libcfa/rational	(revision 561f7308676f4263e3d2c5d41e9c1cf1d336fd5f)
@@ -12,6 +12,6 @@
 // Created On       : Wed Apr  6 17:56:25 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Mon May  1 08:25:06 2017
-// Update Count     : 33
+// Last Modified On : Sun May 14 16:49:13 2017
+// Update Count     : 78
 //
 
@@ -21,49 +21,124 @@
 #include "iostream"
 
+trait scalar( otype T ) {
+};
+
+trait arithmetic( otype T | scalar( T ) ) {
+	int !?( T );
+	int ?==?( T, T );
+	int ?!=?( T, T );
+	int ?<?( T, T );
+	int ?<=?( T, T );
+	int ?>?( T, T );
+	int ?>=?( T, T );
+	void ?{}( T *, zero_t );
+	void ?{}( T *, one_t );
+	T +?( T );
+	T -?( T );
+	T ?+?( T, T );
+	T ?-?( T, T );
+	T ?*?( T, T );
+	T ?/?( T, T );
+	T ?%?( T, T );
+	T ?/=?( T *, T );
+	T abs( T );
+};
+
 // implementation
-typedef long int RationalImpl;
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
 struct Rational {
-	RationalImpl numerator, denominator;					// invariant: denominator > 0
+	RationalImpl numerator, denominator;				// invariant: denominator > 0
 }; // Rational
 
-// constants
-extern struct Rational 0;
-extern struct Rational 1;
+// constructors
 
-// constructors
-void ?{}( Rational * r );
-void ?{}( Rational * r, RationalImpl n );
-void ?{}( Rational * r, RationalImpl n, RationalImpl d );
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+void ?{}( Rational(RationalImpl) * r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+void ?{}( Rational(RationalImpl) * r, RationalImpl n );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+void ?{}( Rational(RationalImpl) * r, RationalImpl n, RationalImpl d );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+void ?{}( Rational(RationalImpl) * r, zero_t );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+void ?{}( Rational(RationalImpl) * r, one_t );
 
 // getter for numerator/denominator
-RationalImpl numerator( Rational r );
-RationalImpl denominator( Rational r );
-[ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational src );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+RationalImpl numerator( Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+RationalImpl denominator( Rational(RationalImpl) r );
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+[ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
+
 // setter for numerator/denominator
-RationalImpl numerator( Rational r, RationalImpl n );
-RationalImpl denominator( Rational r, RationalImpl d );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d );
 
 // comparison
-int ?==?( Rational l, Rational r );
-int ?!=?( Rational l, Rational r );
-int ?<?( Rational l, Rational r );
-int ?<=?( Rational l, Rational r );
-int ?>?( Rational l, Rational r );
-int ?>=?( Rational l, Rational r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
 
 // arithmetic
-Rational -?( Rational r );
-Rational ?+?( Rational l, Rational r );
-Rational ?-?( Rational l, Rational r );
-Rational ?*?( Rational l, Rational r );
-Rational ?/?( Rational l, Rational r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+Rational(RationalImpl) +?( Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+Rational(RationalImpl) -?( Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r );
 
 // conversion
-double widen( Rational r );
-Rational narrow( double f, RationalImpl md );
+// forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+// double widen( Rational(RationalImpl) r );
+// forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+// Rational(RationalImpl) narrow( double f, RationalImpl md );
 
 // I/O
-forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
-forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } )
+istype * ?|?( istype *, Rational(RationalImpl) * );
+
+forall ( otype RationalImpl | arithmetic( RationalImpl ) )
+forall( dtype ostype | ostream( ostype ) | { ostype * ?|?( ostype *, RationalImpl ); } )
+ostype * ?|?( ostype *, Rational(RationalImpl ) );
 
 #endif // RATIONAL_H
