CoxIter  1.2
CoxIter - Computing invariants of hyperbolic Coxeter groups
rational.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2013, 2014, 2016, 2016
3 Rafael Guglielmetti, rafael.guglielmetti@unifr.ch
4 */
5 
6 /*
7 This file is part of CoxIter.
8 
9 CoxIter is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as
11 published by the Free Software Foundation, either version 3 of the
12 License, or (at your option) any later version.
13 
14 CoxIter is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with CoxIter. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
30 #ifndef __RATIONAL_GENERIC_H__
31 #define __RATIONAL_GENERIC_H__
32 
33 #include <iostream>
34 
35 using namespace std;
36 
37 template <typename T>
38 class Rational
39 {
40  public:
41  T a;
42  T b;
43 
44  private:
45  // TODO init
46  bool isZero;
48  bool isOne;
49  bool isMinusOne;
50 
51  private:
55  void update( );
56 
57  public:
58  Rational( );
59 
60  Rational( T a, T b );
61  Rational( T a );
62 
63  Rational( const int& i );
64 
65  bool operator>( Rational const& ) const;
66  bool operator>=( int const& ) const;
67  bool operator==( int const& ) const;
68  bool operator==( Rational const& ) const;
69  bool operator!=( Rational const& ) const;
70 
71  Rational& operator=( long int );
72 
73  Rational operator+( Rational const &n ) const;
74  Rational& operator+=( Rational const &n );
75 
76  Rational operator-( Rational const &n ) const;
77  Rational operator-( ) const;
78  void opp( Rational* &_c ) const;
79  Rational& operator-=( Rational const &n );
80 
81  Rational operator*( Rational const &n ) const;
82  Rational& operator*=( Rational const &n );
83 
84  Rational operator/( Rational const &n ) const;
85  Rational& operator/=( Rational const &n );
86 
87  void print( ostream & ) const;
88 
89  string to_string( ) const;
90 
91  bool get_hasDenominatorOne() const;
92 };
93 
94 template <typename T>
95 ostream& operator<<( ostream& , Rational<T> const & );
96 
97 template <typename T>
98 T abs( const T& r )
99 {
100  T rabs( r );
101  if( rabs.a.bIsLessThan( 0 ) )
102  rabs.a.multiplyBy( -1 );
103 
104  return rabs;
105 }
106 
107 #include "rational.tpp"
108 
109 #endif
T abs(const T &r)
Definition: rational.h:98
Definition: rational.h:38
T b
Definition: rational.h:42
bool operator==(const Graph &g1, const Graph &g2)
Definition: graph.cpp:918
bool hasDenominatorOne
Definition: rational.h:47
T a
Definition: rational.h:41
bool isZero
Definition: rational.h:46
bool isOne
Definition: rational.h:48
bool isMinusOne
Definition: rational.h:49