CoxIter  1.3
CoxIter - Computing invariants of hyperbolic Coxeter groups
rational.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2013-2017
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> class Rational {
38 public:
39  T a;
40  T b;
41 
42 private:
43  // TODO init
44  bool isZero;
46  bool isOne;
47  bool isMinusOne;
48 
49 private:
53  void update();
54 
55 public:
57 
58  Rational(T a, T b);
59  Rational(T a);
60 
61  Rational(const int &i);
62 
63  bool operator>(Rational const &) const;
64  bool operator<(Rational const &) const;
65  bool operator>=(int const &) const;
66  bool operator==(int const &) const;
67  bool operator==(Rational const &) const;
68  bool operator!=(Rational const &) const;
69 
70  Rational &operator=(long int);
71 
72  Rational operator+(Rational const &n) const;
74 
75  Rational operator-(Rational const &n) const;
77  void opp(Rational *&_c) const;
79 
80  Rational operator*(Rational const &n) const;
82 
83  Rational operator/(Rational const &n) const;
85 
86  void print(ostream &) const;
87 
88  string to_string() const;
89 
90  bool get_hasDenominatorOne() const;
91 };
92 
93 template <typename T> ostream &operator<<(ostream &, Rational<T> const &);
94 
95 template <typename T> T abs(const T &r) {
96  T rabs(r);
97  if (rabs.a.isLessThan(0))
98  rabs.a.multiplyBy(-1);
99 
100  return rabs;
101 }
102 
103 #include "rational.tpp"
104 
105 #endif
Definition: rational.h:37
Rational & operator*=(Rational const &n)
string to_string() const
Rational(T a)
Rational operator-() const
Rational & operator/=(Rational const &n)
bool operator<(Rational const &) const
Rational & operator=(long int)
bool operator==(Rational const &) const
T a
Definition: rational.h:39
bool operator>=(int const &) const
Rational operator-(Rational const &n) const
Rational & operator-=(Rational const &n)
Rational operator+(Rational const &n) const
bool isOne
Definition: rational.h:46
T b
Definition: rational.h:40
Rational(const int &i)
void print(ostream &) const
bool hasDenominatorOne
Definition: rational.h:45
bool operator==(int const &) const
Rational(T a, T b)
Rational & operator+=(Rational const &n)
bool operator!=(Rational const &) const
void update()
Met à jour les attributs (gcd, isInt, ...)
Rational operator*(Rational const &n) const
bool operator>(Rational const &) const
Rational operator/(Rational const &n) const
bool get_hasDenominatorOne() const
void opp(Rational *&_c) const
bool isMinusOne
Definition: rational.h:47
bool isZero
Definition: rational.h:44
ostream & operator<<(ostream &, Rational< T > const &)
T abs(const T &r)
Definition: rational.h:95