source: src/libcfa/rational @ d3a85240

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since d3a85240 was 17e5e2b, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Added proper include guards to cfa headers so they can be added to the c++ include path without issues

  • Property mode set to 100644
File size: 2.1 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
13// Last Modified By : Peter A. Buhr
14// Last Modified On : Wed May  4 14:11:45 2016
15// Update Count     : 16
16//
17#ifdef __CFORALL__
18
19#ifndef RATIONAL_H
20#define RATIONAL_H
21
22#include "iostream"
23
24// implementation
25struct Rational {
26        long int numerator, denominator;                                        // invariant: denominator > 0
27}; // Rational
28
29// constants
30extern struct Rational 0;
31extern struct Rational 1;
32
33// constructors
34void ?{}( Rational * r );
35void ?{}( Rational * r, long int n );
36void ?{}( Rational * r, long int n, long int d );
37
38// getter/setter for numerator/denominator
39long int numerator( Rational r );
40long int numerator( Rational r, long int n );
41long int denominator( Rational r );
42long int denominator( Rational r, long int d );
43
44// comparison
45int ?==?( Rational l, Rational r );
46int ?!=?( Rational l, Rational r );
47int ?<?( Rational l, Rational r );
48int ?<=?( Rational l, Rational r );
49int ?>?( Rational l, Rational r );
50int ?>=?( Rational l, Rational r );
51
52// arithmetic
53Rational -?( Rational r );
54Rational ?+?( Rational l, Rational r );
55Rational ?-?( Rational l, Rational r );
56Rational ?*?( Rational l, Rational r );
57Rational ?/?( Rational l, Rational r );
58
59// conversion
60double widen( Rational r );
61Rational narrow( double f, long int md );
62
63// I/O
64forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
65forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
66
67#endif // RATIONAL_H
68
69#else
70#include_next <rational>
71#endif //__CFORALL__
72
73// Local Variables: //
74// mode: c //
75// tab-width: 4 //
76// End: //
Note: See TracBrowser for help on using the repository browser.