// // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // rational -- // // Author : Peter A. Buhr // Created On : Wed Apr 6 17:56:25 2016 // Last Modified By : Peter A. Buhr // Last Modified On : Thu Apr 7 17:23:36 2016 // Update Count : 9 // #include "iostream" struct Rational { long int numerator, denominator; // invariant: denominator > 0 }; // Rational extern struct Rational 0; extern struct Rational 1; long int gcd( long int a, long int b ); long int simplify( long int *n, long int *d ); Rational rational(); // constructor Rational rational( long int n ); // constructor Rational rational( long int n, long int d ); // constructor long int numerator( Rational r ); long int numerator( Rational r, long int n ); long int denominator( Rational r, long int d ); int ?==?( Rational l, Rational r ); int ?!=?( Rational l, Rational r ); int ??( Rational l, Rational r ); int ?>=?( Rational l, Rational r ); Rational -?( Rational r ); Rational ?+?( Rational l, Rational r ); Rational ?-?( Rational l, Rational r ); Rational ?*?( Rational l, Rational r ); Rational ?/?( Rational l, Rational r ); double widen( Rational r ); Rational narrow( double f, long int md ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational ); // Local Variables: // // mode: c // // tab-width: 4 // // End: //