-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyFloat.h
64 lines (53 loc) · 986 Bytes
/
MyFloat.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// Created by davilka on 09.11.17.
//
#pragma once
#ifndef FLOAT_MYFLOAT_H
#define FLOAT_MYFLOAT_H
class MyFloat {
private:
int mant;
int expn;
public:
MyFloat() {}
MyFloat(double v) {
int e=0;
while (v >= 1 || v <= -1) {
v /= 2;
e++;
}
while ((v > 0 && v < 0.5) || (v > -0.5 && v < 0)) {
v *= 2;
e--;
}
setMant((int) (v * 10000));
setExp(e);
}
MyFloat(int m, int e) {
while (m >= 10000 || m <= -10000) {
m /= 2;
e++;
}
while ((m > 0 && m < 5000) || (m > -5000 && m < 0)) {
m *= 2;
e--;
}
setMant(m);
setExp(e);
}
MyFloat(MyFloat const &f) {
setMant(f.mant);
setExp(f.expn);
}
void print();
double restore();
int getMant();
int getExp();
void setMant(int);
void setExp(int);
friend MyFloat operator +(MyFloat, MyFloat);
friend MyFloat operator -(MyFloat, MyFloat);
friend MyFloat operator *(MyFloat, MyFloat);
friend MyFloat operator /(MyFloat, MyFloat);
};
#endif //FLOAT_MYFLOAT_H