# source:src/libcfa/rational@d1ab533

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since d1ab533 was d1ab533, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

• Property mode set to `100644`
File size: 2.0 KB
Line
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// rational -- Rational numbers are numbers written as a ratio, i.e., as a fraction, where the numerator (top number)
8//     and the denominator (bottom number) are whole numbers. When creating and computing with rational numbers, results
9//     are constantly reduced to keep the numerator and denominator as small as possible.
10//
11// Author           : Peter A. Buhr
12// Created On       : Wed Apr  6 17:56:25 2016
15// Update Count     : 16
16//
17
18#include "iostream"
19
20// implementation
21struct Rational {
22        long int numerator, denominator;                                        // invariant: denominator > 0
23}; // Rational
24
25// constants
26extern struct Rational 0;
27extern struct Rational 1;
28
29// constructors
30void ?{}( Rational * r );
31void ?{}( Rational * r, long int n );
32void ?{}( Rational * r, long int n, long int d );
33
34// getter/setter for numerator/denominator
35long int numerator( Rational r );
36long int numerator( Rational r, long int n );
37long int denominator( Rational r );
38long int denominator( Rational r, long int d );
39
40// comparison
41int ?==?( Rational l, Rational r );
42int ?!=?( Rational l, Rational r );
43int ?<?( Rational l, Rational r );
44int ?<=?( Rational l, Rational r );
45int ?>?( Rational l, Rational r );
46int ?>=?( Rational l, Rational r );
47
48// arithmetic
49Rational -?( Rational r );
50Rational ?+?( Rational l, Rational r );
51Rational ?-?( Rational l, Rational r );
52Rational ?*?( Rational l, Rational r );
53Rational ?/?( Rational l, Rational r );
54
55// conversion
56double widen( Rational r );
57Rational narrow( double f, long int md );
58
59// I/O
60forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
61forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
62
63// Local Variables: //
64// mode: c //
65// tab-width: 4 //
66// End: //
Note: See TracBrowser for help on using the repository browser.