source: src/libcfa/rational @ e04c5ff

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since e04c5ff was d1ab5331, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

add constructors to rational type

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[53ba273]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//
[630a82a]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.
[53ba273]10//
11// Author           : Peter A. Buhr
12// Created On       : Wed Apr  6 17:56:25 2016
13// Last Modified By : Peter A. Buhr
[d1ab5331]14// Last Modified On : Wed May  4 14:11:45 2016
15// Update Count     : 16
[53ba273]16//
17
[3d9b5da]18#include "iostream"
[53ba273]19
[630a82a]20// implementation
[53ba273]21struct Rational {
22        long int numerator, denominator;                                        // invariant: denominator > 0
23}; // Rational
24
[630a82a]25// constants
[53ba273]26extern struct Rational 0;
27extern struct Rational 1;
28
[630a82a]29// constructors
[d1ab5331]30void ?{}( Rational * r );
31void ?{}( Rational * r, long int n );
32void ?{}( Rational * r, long int n, long int d );
[630a82a]33
34// getter/setter for numerator/denominator
[53ba273]35long int numerator( Rational r );
36long int numerator( Rational r, long int n );
[630a82a]37long int denominator( Rational r );
[53ba273]38long int denominator( Rational r, long int d );
[630a82a]39
40// comparison
[53ba273]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 );
[630a82a]47
48// arithmetic
[53ba273]49Rational -?( Rational r );
50Rational ?+?( Rational l, Rational r );
51Rational ?-?( Rational l, Rational r );
52Rational ?*?( Rational l, Rational r );
53Rational ?/?( Rational l, Rational r );
[630a82a]54
55// conversion
[53ba273]56double widen( Rational r );
57Rational narrow( double f, long int md );
[630a82a]58
59// I/O
[3d9b5da]60forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
61forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
[53ba273]62
63// Local Variables: //
64// mode: c //
65// tab-width: 4 //
66// End: //
Note: See TracBrowser for help on using the repository browser.