-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTest.cpp
More file actions
129 lines (107 loc) · 3.64 KB
/
Test.cpp
File metadata and controls
129 lines (107 loc) · 3.64 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include "BigFloat.h"
int main()
{
//Test
BigFloat a, b, c;
//NaN test
std::cout << a << std::endl;
std::cout << a.ToDouble() << std::endl;
std::cout << a.ToFloat() << std::endl;
std::cout << a.ToString() << std::endl;
std::cout << std::endl;
//Error Codes test
if(a.HasError())
std::cout << a.GetError() << std::endl;
a = 11.5;
if(a.HasError())
std::cout << a.GetError() << std::endl;
b = a % 2;
std::cout << b.GetError() << std::endl;
b = 15;
std::cout << b.GetError() << std::endl;
b = a / 0;
std::cout << b.GetError() << std::endl;
std::cout << std::endl;
//Assignation,SetPrecision,Trim test
BigFloat d(a);
std::cout << "d " << d << std::endl;
d = -14.34434340000;
std::cout << "d " << d << std::endl;
d = "000.645343400000";
std::cout << "d " << d << std::endl;
std::cout << "d dec " << d.Decimals() << std::endl;
d.TrailTrim();
d.LeadTrim();
std::cout << "d " << d << std::endl;
d.SetPrecision(2);
std::cout << "d set(2) " << d << std::endl;
d.SetPrecision(0);
std::cout << "d set(0) " << d << std::endl;
d = "-1000.12323";
std::cout << "d exp " << d.Exp() << std::endl;
d = "-1.1223222";
std::cout << "d exp " << d.Exp() << std::endl;
d = "-1";
std::cout << "d exp " << d.Exp() << std::endl;
d = "-0.0000123453434";
std::cout << "d exp " << d.Exp() << std::endl;
d = "-0.0000000000000";
std::cout << "d exp " << d.Exp() << std::endl;
std::cout << std::endl;
std::cout << "Inserisci 2 numeri:" << std::endl;
std::cin >> a >> b;
std::cout << std::endl;
std::cout << "a " << a << "\tb " << b << std::endl;
std::cout << std::endl;
//Operations +,-,*,/ Test
c = a + b;
std::cout << "a+b " << c << std::endl;
c = a - b;
std::cout << "a-b " << c << std::endl;
c = a * b;
std::cout << "a*b " << c << std::endl;
c = a / b;
std::cout << "a/b " << c << std::endl;
c = BigFloat::PrecDiv(a, b, 10);
std::cout << "PrecDiv(a,b,10) " << c << std::endl;
c = a % b;
std::cout << "a%b " << c << std::endl;
c = BigFloat::Power(a, b);
std::cout << "Power(a,b) " << c << std::endl;
c = BigFloat::Power(a, b, 10); //for negative exponents
std::cout << "Power(a,b,10) " << c << std::endl;
//Comparation Test
std::cout << std::endl;
std::cout << "a==b " << (a == b) << std::endl;
std::cout << "a>b " << (a > b) << std::endl;
std::cout << "a<b " << (a < b) << std::endl;
std::cout << "a>=b " << (a >= b) << std::endl;
std::cout << "a<=b " << (a <= b) << std::endl;
//Transformation Test
std::cout << std::endl;
std::cout << "ToDouble " << a.ToDouble() << std::endl;
std::cout << "ToFloat " << a.ToFloat() << std::endl;
std::cout << "ToString " << a.ToString() << std::endl;
std::cout << std::endl;
std::cout << "(double) " << (double)a << std::endl;
std::cout << "(float) " << (float)a << std::endl;
std::cout << "(string) " << (std::string)a << std::endl;
//++,-- Test
std::cout << std::endl;
std::cout << "a++ " << a++ << std::endl;
std::cout << "++a " << ++a << std::endl;
std::cout << "a-- " << a-- << std::endl;
std::cout << "--a " << --a << std::endl;
a += 666;
a -= 123;
a *= 3.14;
a /= 2.71f;
std::cout << "a after some manipulations: " << a << std::endl;
//Miscellaneous test
std::cout << std::endl;
std::cout << "a ints " << a.Ints() << std::endl;
std::cout << "a decimals " << a.Decimals() << std::endl;
std::cout << "a memory size " << a.MemorySize() << std::endl;
return 0;
}