-
Notifications
You must be signed in to change notification settings - Fork 0
/
fps.cpp
48 lines (41 loc) · 875 Bytes
/
fps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "fps.h"
fps::fps() {
num = 0;
exponent = 0;
}
fps::fps(bnum n, bnum ps) {
exponent = ps;
num = n % exponent;
if(num < 0) num += exponent;
}
fps fps::operator+(fps b) {
fps tmp;
if(exponent != b.exponent) return tmp;
tmp.exponent = exponent;
tmp.num = (num + b.num) % exponent;
if(tmp.num < 0) tmp.num += exponent;
return tmp;
}
fps fps::operator-(fps b) {
fps tmp;
if(exponent != b.exponent) return tmp;
tmp.exponent = exponent;
tmp.num = (num - b.num) % exponent;
if(tmp.num < 0) tmp.num += exponent;
return tmp;
}
fps fps::operator*(fps b) {
fps tmp;
if(exponent != b.exponent) return tmp;
tmp.exponent = exponent;
tmp.num = num * b.num % exponent;
if(tmp.num < 0) tmp.num += exponent;
return tmp;
}
void fps::operator=(bnum b) {
num = b % exponent;
if(num < 0) num += exponent;
}
int main() {
return 0;
}