Project

General

Profile

Statistics
| Branch: | Revision:

cool / src / lib / GMLMIP-0.1 / formulas / rational.c @ 7c4d2eb4

History | View | Annotate | Download (517 Bytes)

1 e034e268 Thorsten WiƟmann
#include "rational.h"
2
3
Rational::Rational(int i){
4
        if(i==-1){ //For empty key in hash maps
5
                top = 0;
6
                bottom = 0;
7
        }
8
        else{
9
        top = i;
10
        bottom = 1;
11
        }
12
}
13
14
double Rational::get(){ 
15
        return (static_cast<double>(top)/bottom);
16
}
17
                
18
ostream& operator<<(ostream &o, const Rational &r){
19
        o << r.top << "/" << r.bottom;
20
        return o;
21
}
22
                
23
bool operator==(const Rational &r1, const Rational &r2){
24
        return((r1.top*r2.bottom) == (r2.top*r1.bottom));
25
}
26
27
bool operator!=(const Rational &r1, const Rational &r2){
28
        return !(r1==r2);
29
}