source: src/libcfa/rational @ bb82c03

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since bb82c03 was bb82c03, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Removed #ifdef for CFORALL in libcfa headers

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