Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
Rational.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MODEL is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_Rational_h_
9#define model_Rational_h_
10
11#include <Eigen/Core>
12
13#include <ostream>
14
15namespace model
16{
18 {
19
20 /**********************************************************************/
21 static int gcd(const size_t &a, const size_t &b);
22
23 /**********************************************************************/
24 static int sgn(const long int &a);
25
26 public:
27 long int n; // numerator
28 long int d; // denominator
29
30 Rational();
31
32 Rational(const long int &n_in);
33
34 Rational(const long int &n_in, const long int &d_in);
35
36 double asDouble() const;
37
38 bool operator==(const long int &other) const;
39
40 bool operator!=(const long int &other) const;
41
42 Rational operator*(const Rational &r2) const;
43
44 Rational operator/(const Rational &r2) const;
45
46 Rational operator+(const Rational &r2) const;
47
48 Rational operator-(const Rational &r2) const;
49
50 Rational operator*(const long int &i) const;
51
52 Rational operator/(const long int &i) const;
53
54 Rational operator+(const long int &i) const;
55
56 Rational operator-(const long int &i) const;
57
58 /*************************************************************/
59 // friend T& operator <<
60 // template <class T>
61 friend std::ostream &operator<<(std::ostream &os, const Rational &r);
62 };
63
64 // Rational rat(const long int& n,const long int& d)
65 // {
66 // return Rational(n,d);
67 // }
68
69} // namespace model
70
71namespace Eigen
72{
73 template <>
74 struct NumTraits<model::Rational>
75 : NumTraits<long int> // permits to get the epsilon, dummy_precision, lowest, highest functions
76 {
77 typedef long int Real;
78 typedef long int NonInteger;
79 typedef long int Nested;
80 enum
81 {
89 };
90 };
91} // namespace Eigen
92
93#endif
Rational operator-(const long int &i) const
Rational operator/(const long int &i) const
long int d
Definition Rational.h:28
bool operator==(const long int &other) const
friend std::ostream & operator<<(std::ostream &os, const Rational &r)
Definition Rational.cpp:98
long int n
Definition Rational.h:27
Rational operator-(const Rational &r2) const
Rational operator*(const Rational &r2) const
Rational operator+(const Rational &r2) const
double asDouble() const
bool operator!=(const long int &other) const
Rational operator*(const long int &i) const
Rational operator/(const Rational &r2) const
Rational operator+(const long int &i) const
a
Definition int_R.m:14
b
Definition int_R.m:16
int i