-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcorrect_all_flags.d
65 lines (53 loc) · 2.39 KB
/
correct_all_flags.d
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
import std.stdio;
import std.datetime: MonoTime;
import std.random;
import std.math;
import f1 = format_old;
import f2 = format_new;
void main(string[] args)
{
FloatingPointControl fpctrl;
auto r_tab = [FloatingPointControl.roundDown, FloatingPointControl.roundUp,
FloatingPointControl.roundToZero, FloatingPointControl.roundToNearest];
auto f_tab = [float.nan, float.infinity, -float.nan, -float.infinity, 0.0, -0.0,
1.0,0.1,1e10,1e-10,1e20,1e-20,1e30,1e-30,1e-40,
1.23456789,1.23456789e10,1.23456789e20,1.23456789e30,
1.23456789e-1,1.23456789e-10,1.23456789e-20,1.23456789e-30,
-1.0,-0.1,-1e10,-1e-10,-1e20,-1e-20,-1e30,-1e-30,-1e-40,
-1.23456789,-1.23456789e10,-1.23456789e20,-1.23456789e30,
-1.23456789e-1,-1.23456789e-10,-1.23456789e-20,-1.23456789e-30,
-29610.9609375, 26535.5078125,
0.1,0.02,0.003,0.004,0.0005,0.00006,0.000007,0.0000008,0.00000009,
10,200,3000,40000,500000,6000000,70000000,8000000000,90000000000];
auto w_tab = ["", "0", "1", "5", "10", "25", "100", "125", "200"];
auto p_tab = ["", ".0", ".1", ".5", ".10", ".25", ".100", ".125", ".200"];
auto s_tab = "fF";
ulong count = 0;
ulong correct = 0;
foreach (r;r_tab)
{
fpctrl.rounding = r;
foreach (f;f_tab)
foreach (flag;0..32)
foreach (width;w_tab)
foreach (precision;p_tab)
foreach (spec;s_tab)
{
string format = "%"
~ ((flag&1)==0?"-":"")
~ ((flag&2)==0?"+":"")
~ ((flag&4)==0?" ":"")
~ ((flag&8)==0?"0":"")
~ ((flag&16)==0?"#":"")
~ width
~ precision
~ spec;
float ff = f; // make sure we have a float
string r_old = f1.format(format,ff);
string r_new = f2.format(format,ff);
++count;
if (r_old==r_new) ++correct;
}
}
writefln!"checks: %d\ncorrect: %d"(count,correct);
}