-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatTypes.cpp
More file actions
78 lines (72 loc) · 1.87 KB
/
Copy pathFloatTypes.cpp
File metadata and controls
78 lines (72 loc) · 1.87 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
# include "FloatTypes.h"
// A constructor
Rfloat :: Rfloat()
{
n = 0;
generator.seed(system_clock :: now().time_since_epoch().count());
}
// A function that generates a uniformly random floating point number
void Rfloat :: generate(float l, float r)
{
uniform_real_distribution <float> distribution(l, r);
n = distribution(generator);
}
// A function that generates floating point test case files
void Rfloat :: setCase(string &s, int T, int t, float l, float r, string &folder_name)
{
int pt = FileOp :: printT(t);
FileOp :: fixOutprecision(fout);
cout << "Generating float test files: " << '\n';
for(int i = 0; i < T; i++)
{
FileOp :: setFile(folder_name, s, i, fout);
int times = numOp :: giveRint(t);
if(pt)
fout << times << '\n';
Timer t1(times);
for(int j = 0; j < times; j++)
{
generate(l, r);
fout << n << '\n';
t1.time(1);
}
fout.close();
}
cout << "float generation completed." << '\n';
}
// A constructor
Rfpair :: Rfpair()
{
a = b = 0;
generator.seed(system_clock :: now().time_since_epoch().count());
}
// A function that generates a uniformly random floating point pair
void Rfpair :: generate(float l, float r)
{
uniform_real_distribution <float> distribution(l, r);
a = distribution(generator);
b = distribution(generator);
}
// A function that generates floating point pair test case files
void Rfpair :: setCase(string &s, int T, int t, float l, float r, string &folder_name)
{
int pt = FileOp :: printT(t);
FileOp :: fixOutprecision(fout);
cout << "Generating fpair test files: " << '\n';
for(int i = 0; i < T; i++)
{
FileOp :: setFile(folder_name, s, i, fout);
int times = numOp :: giveRint(t);
if(pt)
fout << times << '\n';
Timer t1(2 * times);
for(int j = 0; j < times; j++)
{
generate(l, r);
fout << a << ' ' << b << '\n';
t1.time(2);
}
fout.close();
}
cout << "fpair generation completed." << '\n';
}