# source:src/libcfa/rational@f621a148

Last change on this file since f621a148 was f621a148, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

change to implementation type for rational and add to test suite

• Property mode set to `100644`
File size: 2.2 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     : 33
16//
17
18#ifndef RATIONAL_H
19#define RATIONAL_H
20
21#include "iostream"
22
23// implementation
24typedef long int RationalImpl;
25struct Rational {
26        RationalImpl 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, RationalImpl n );
36void ?{}( Rational * r, RationalImpl n, RationalImpl d );
37
38// getter for numerator/denominator
39RationalImpl numerator( Rational r );
40RationalImpl denominator( Rational r );
41[ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational src );
42// setter for numerator/denominator
43RationalImpl numerator( Rational r, RationalImpl n );
44RationalImpl denominator( Rational r, RationalImpl d );
45
46// comparison
47int ?==?( Rational l, Rational r );
48int ?!=?( Rational l, Rational r );
49int ?<?( Rational l, Rational r );
50int ?<=?( Rational l, Rational r );
51int ?>?( Rational l, Rational r );
52int ?>=?( Rational l, Rational r );
53
54// arithmetic
55Rational -?( Rational r );
56Rational ?+?( Rational l, Rational r );
57Rational ?-?( Rational l, Rational r );
58Rational ?*?( Rational l, Rational r );
59Rational ?/?( Rational l, Rational r );
60
61// conversion
62double widen( Rational r );
63Rational narrow( double f, RationalImpl md );
64
65// I/O
66forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
67forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
68
69#endif // RATIONAL_H
70
71// Local Variables: //
72// mode: c //
73// tab-width: 4 //
74// End: //
Note: See TracBrowser for help on using the repository browser.