forked from coder-mike/FixedPoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.cpp
More file actions
59 lines (43 loc) · 1.39 KB
/
examples.cpp
File metadata and controls
59 lines (43 loc) · 1.39 KB
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
#include "fixed_point.hpp"
#include <iostream>
#define PRINT_VAL(VAL) std::cout << #VAL << ":\t" << (VAL) << std::endl
OverflowMode OVERFLOW_MODE = OverflowMode::CLAMP;
void assignment_test(){
// Something is wrong here
FixedPoint<0, 1> aa = 1;
PRINT_VAL(aa);
FixedPoint<0, 5> aaa = 1;
PRINT_VAL(aaa);
// This uses 8 bits in this case, need to cast the number to the right type every time!
FixedPoint<0, 0> aaaa = 127;
PRINT_VAL(aaaa);
FixedPoint<0, 0> aaaaa = 128;
PRINT_VAL(aaaaa);
FixedPoint<0, 2> bb = 1;
PRINT_VAL(bb);
FixedPoint<0, 2> cc = 2;
PRINT_VAL(cc);
FixedPoint<1, 1> a(1);
std::cout << "a: " << a << std::endl;
FixedPoint<2, 2> b(1);
std::cout << "b: " << b << std::endl;
FixedPoint<2, 2> c(2);
std::cout << "c: " << c << std::endl;
FixedPoint<2, 2> d(3);
std::cout << "d: " << d << std::endl;
FixedPoint<2, 2> e(4);
std::cout << "e: " << e << std::endl;
FixedPoint<2, 2> f(5);
std::cout << "f: " << f << std::endl;
FixedPoint<2, 2> g = 6;
std::cout << "g: " << g << std::endl;
FixedPoint<2, 2> h = 70;
std::cout << "h: " << h << std::endl;
//!!!!!!
FixedPoint<6, 10> div_test = 0.028;
std::cout << "div_test: " << div_test << std::endl;
std::cout << "div_test: " << FixedPoint<6, 10>(1)/div_test << std::endl;
}
int main(){
assignment_test();
}