//
// 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 -- Rational numbers are numbers written as a ratio, i.e., as a fraction, where the numerator (top number)
//     and the denominator (bottom number) are whole numbers. When creating and computing with rational numbers, results
//     are constantly reduced to keep the numerator and denominator as small as possible.
//
// Author           : Peter A. Buhr
// 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
//

#ifndef RATIONAL_H
#define RATIONAL_H

#include "iostream"

// implementation
typedef long int RationalImpl;
struct Rational {
	RationalImpl numerator, denominator;					// invariant: denominator > 0
}; // Rational

// constants
extern struct Rational 0;
extern struct Rational 1;

// constructors
void ?{}( Rational * r );
void ?{}( Rational * r, RationalImpl n );
void ?{}( Rational * r, RationalImpl n, RationalImpl d );

// getter for numerator/denominator
RationalImpl numerator( Rational r );
RationalImpl denominator( Rational r );
[ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational src );
// setter for numerator/denominator
RationalImpl numerator( Rational r, RationalImpl n );
RationalImpl denominator( Rational 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 );

// arithmetic
Rational -?( Rational r );
Rational ?+?( Rational l, Rational r );
Rational ?-?( Rational l, Rational r );
Rational ?*?( Rational l, Rational r );
Rational ?/?( Rational l, Rational r );

// conversion
double widen( Rational r );
Rational narrow( double f, RationalImpl md );

// I/O
forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );

#endif // RATIONAL_H

// Local Variables: //
// mode: c //
// tab-width: 4 //
// End: //
