Index: src/libcfa/rational.c
===================================================================
--- src/libcfa/rational.c	(revision 09687aa36e045a9f891425c68a40a1b26dc5f632)
+++ src/libcfa/rational.c	(revision b21c77a0e211d9361763565a2eb5ef4330f2957b)
@@ -10,6 +10,6 @@
 // Created On       : Wed Apr  6 17:54:28 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Dec  6 23:13:58 2017
-// Update Count     : 156
+// Last Modified On : Sat Jun  2 09:24:33 2018
+// Update Count     : 162
 //
 
@@ -18,173 +18,166 @@
 #include "stdlib"
 
-// helper routines
-
-// Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce rationals.
-// alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-static RationalImpl gcd( RationalImpl a, RationalImpl b ) {
-	for ( ;; ) {										// Euclid's algorithm
-		RationalImpl r = a % b;
-	  if ( r == (RationalImpl){0} ) break;
-		a = b;
-		b = r;
-	} // for
-	return b;
-} // gcd
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) {
-	if ( d == (RationalImpl){0} ) {
-		serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl;
-		exit( EXIT_FAILURE );
-	} // exit
-	if ( d < (RationalImpl){0} ) { d = -d; n = -n; }	// move sign to numerator
-	return gcd( abs( n ), d );							// simplify
-} // Rationalnumber::simplify
-
-
-// constructors
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r ) {
-	r{ (RationalImpl){0}, (RationalImpl){1} };
-} // rational
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r, RationalImpl n ) {
-	r{ n, (RationalImpl){1} };
-} // rational
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ) {
-	RationalImpl t = simplify( n, d );					// simplify
-	r.numerator = n / t;
-	r.denominator = d / t;
-} // rational
-
-
-// getter for numerator/denominator
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl numerator( Rational(RationalImpl) r ) {
-	return r.numerator;
-} // numerator
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl denominator( Rational(RationalImpl) r ) {
-	return r.denominator;
-} // denominator
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) {
-	return dest = src.[ numerator, denominator ];
-}
-
-// setter for numerator/denominator
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ) {
-	RationalImpl prev = r.numerator;
-	RationalImpl t = gcd( abs( n ), r.denominator );		// simplify
-	r.numerator = n / t;
-	r.denominator = r.denominator / t;
-	return prev;
-} // numerator
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) {
-	RationalImpl prev = r.denominator;
-	RationalImpl t = simplify( r.numerator, d );			// simplify
-	r.numerator = r.numerator / t;
-	r.denominator = d / t;
-	return prev;
-} // denominator
-
-
-// comparison
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return l.numerator * r.denominator == l.denominator * r.numerator;
-} // ?==?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return ! ( l == r );
-} // ?!=?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return l.numerator * r.denominator < l.denominator * r.numerator;
-} // ?<?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return l.numerator * r.denominator <= l.denominator * r.numerator;
-} // ?<=?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return ! ( l <= r );
-} // ?>?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return ! ( l < r );
-} // ?>=?
-
-
-// arithmetic
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) +?( Rational(RationalImpl) r ) {
-	Rational(RationalImpl) t = { r.numerator, r.denominator };
-	return t;
-} // +?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) -?( Rational(RationalImpl) r ) {
-	Rational(RationalImpl) t = { -r.numerator, r.denominator };
-	return t;
-} // -?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	if ( l.denominator == r.denominator ) {				// special case
-		Rational(RationalImpl) t = { l.numerator + r.numerator, l.denominator };
-		return t;
-	} else {
-		Rational(RationalImpl) t = { l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
-		return t;
-	} // if
-} // ?+?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	if ( l.denominator == r.denominator ) {				// special case
-		Rational(RationalImpl) t = { l.numerator - r.numerator, l.denominator };
-		return t;
-	} else {
-		Rational(RationalImpl) t = { l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
-		return t;
-	} // if
-} // ?-?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	Rational(RationalImpl) t = { l.numerator * r.numerator, l.denominator * r.denominator };
-	return t;
-} // ?*?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	if ( r.numerator < (RationalImpl){0} ) {
-		r.numerator = -r.numerator;
-		r.denominator = -r.denominator;
-	} // if
-	Rational(RationalImpl) t = { l.numerator * r.denominator, l.denominator * r.numerator };
-	return t;
-} // ?/?
-
+forall( otype RationalImpl | arithmetic( RationalImpl ) ) {
+	// helper routines
+
+	// Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce
+	// rationals.  alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm
+	static RationalImpl gcd( RationalImpl a, RationalImpl b ) {
+		for ( ;; ) {									// Euclid's algorithm
+			RationalImpl r = a % b;
+		  if ( r == (RationalImpl){0} ) break;
+			a = b;
+			b = r;
+		} // for
+		return b;
+	} // gcd
+
+	static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) {
+		if ( d == (RationalImpl){0} ) {
+			serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl;
+			exit( EXIT_FAILURE );
+		} // exit
+		if ( d < (RationalImpl){0} ) { d = -d; n = -n; } // move sign to numerator
+		return gcd( abs( n ), d );						// simplify
+	} // Rationalnumber::simplify
+
+	// constructors
+
+	void ?{}( Rational(RationalImpl) & r ) {
+		r{ (RationalImpl){0}, (RationalImpl){1} };
+	} // rational
+
+	void ?{}( Rational(RationalImpl) & r, RationalImpl n ) {
+		r{ n, (RationalImpl){1} };
+	} // rational
+
+	void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ) {
+		RationalImpl t = simplify( n, d );				// simplify
+		r.numerator = n / t;
+		r.denominator = d / t;
+	} // rational
+
+
+	// getter for numerator/denominator
+
+	RationalImpl numerator( Rational(RationalImpl) r ) {
+		return r.numerator;
+	} // numerator
+
+	RationalImpl denominator( Rational(RationalImpl) r ) {
+		return r.denominator;
+	} // denominator
+
+	[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) {
+		return dest = src.[ numerator, denominator ];
+	} // ?=?
+
+	// setter for numerator/denominator
+
+	RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ) {
+		RationalImpl prev = r.numerator;
+		RationalImpl t = gcd( abs( n ), r.denominator ); // simplify
+		r.numerator = n / t;
+		r.denominator = r.denominator / t;
+		return prev;
+	} // numerator
+
+	RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) {
+		RationalImpl prev = r.denominator;
+		RationalImpl t = simplify( r.numerator, d );	// simplify
+		r.numerator = r.numerator / t;
+		r.denominator = d / t;
+		return prev;
+	} // denominator
+
+	// comparison
+
+	int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return l.numerator * r.denominator == l.denominator * r.numerator;
+	} // ?==?
+
+	int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return ! ( l == r );
+	} // ?!=?
+
+	int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return l.numerator * r.denominator < l.denominator * r.numerator;
+	} // ?<?
+
+	int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return l.numerator * r.denominator <= l.denominator * r.numerator;
+	} // ?<=?
+
+	int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return ! ( l <= r );
+	} // ?>?
+
+	int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return ! ( l < r );
+	} // ?>=?
+
+	// arithmetic
+
+	Rational(RationalImpl) +?( Rational(RationalImpl) r ) {
+		Rational(RationalImpl) t = { r.numerator, r.denominator };
+		return t;
+	} // +?
+
+	Rational(RationalImpl) -?( Rational(RationalImpl) r ) {
+		Rational(RationalImpl) t = { -r.numerator, r.denominator };
+		return t;
+	} // -?
+
+	Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		if ( l.denominator == r.denominator ) {			// special case
+			Rational(RationalImpl) t = { l.numerator + r.numerator, l.denominator };
+			return t;
+		} else {
+			Rational(RationalImpl) t = { l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
+			return t;
+		} // if
+	} // ?+?
+
+	Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		if ( l.denominator == r.denominator ) {			// special case
+			Rational(RationalImpl) t = { l.numerator - r.numerator, l.denominator };
+			return t;
+		} else {
+			Rational(RationalImpl) t = { l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
+			return t;
+		} // if
+	} // ?-?
+
+	Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		Rational(RationalImpl) t = { l.numerator * r.numerator, l.denominator * r.denominator };
+		return t;
+	} // ?*?
+
+	Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		if ( r.numerator < (RationalImpl){0} ) {
+			r.numerator = -r.numerator;
+			r.denominator = -r.denominator;
+		} // if
+		Rational(RationalImpl) t = { l.numerator * r.denominator, l.denominator * r.numerator };
+		return t;
+	} // ?/?
+
+	// I/O
+
+	forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
+	istype & ?|?( istype & is, Rational(RationalImpl) & r ) {
+		RationalImpl t;
+		is | r.numerator | r.denominator;
+		t = simplify( r.numerator, r.denominator );
+		r.numerator /= t;
+		r.denominator /= t;
+		return is;
+	} // ?|?
+
+	forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } )
+	ostype & ?|?( ostype & os, Rational(RationalImpl ) r ) {
+		return os | r.numerator | '/' | r.denominator;
+	} // ?|?
+} // distribution
 
 // conversion
@@ -195,7 +188,7 @@
 } // widen
 
-// http://www.ics.uci.edu/~eppstein/numth/frap.c
 forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
 Rational(RationalImpl) narrow( double f, RationalImpl md ) {
+	// http://www.ics.uci.edu/~eppstein/numth/frap.c
 	if ( md <= (RationalImpl){1} ) {					// maximum fractional digits too small?
 		return (Rational(RationalImpl)){ convert( f ), (RationalImpl){1}}; // truncate fraction
@@ -224,24 +217,4 @@
 } // narrow
 
-
-// I/O
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
-istype & ?|?( istype & is, Rational(RationalImpl) & r ) {
-	RationalImpl t;
-	is | r.numerator | r.denominator;
-	t = simplify( r.numerator, r.denominator );
-	r.numerator /= t;
-	r.denominator /= t;
-	return is;
-} // ?|?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } )
-ostype & ?|?( ostype & os, Rational(RationalImpl ) r ) {
-	return os | r.numerator | '/' | r.denominator;
-} // ?|?
-
 // Local Variables: //
 // tab-width: 4 //
