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
|
#include <iostream>
#include <iomanip>
struct dsdbl
{
float x, y;
};
dsdbl ds_set(float a)
{
dsdbl z;
z.x = a;
z.y = 0.0;
return z;
}
dsdbl ds_mul(dsdbl dsa, dsdbl dsb)
{
dsdbl dsc;
float c11, c21, c2, e, t1, t2;
float a1, a2, b1, b2, cona, conb, split = 8193.;
cona = dsa.x * split;
conb = dsb.x * split;
a1 = cona - (cona - dsa.x);
b1 = conb - (conb - dsb.x);
a2 = dsa.x - a1;
b2 = dsb.x - b1;
c11 = dsa.x * dsb.x;
c21 = a2 * b2 + (a2 * b1 + (a1 * b2 + (a1 * b1 - c11)));
c2 = dsa.x * dsb.y + dsa.y * dsb.x;
t1 = c11 + c2;
e = t1 - c11;
t2 = dsa.y * dsb.y + ((c2 - e) + (c11 - (t1 - e))) + c21;
dsc.x = t1 + t2;
dsc.y = t2 - (dsc.x - t1);
return dsc;
}
dsdbl ds_add (dsdbl dsa, dsdbl dsb)
{
dsdbl dsc;
float t1, t2, e;
t1 = dsa.x + dsb.x;
e = t1 - dsa.x;
t2 = ((dsb.x - e) + (dsa.x - (t1 - e))) + dsa.y + dsb.y;
dsc.x = t1 + t2;
dsc.y = t2 - (dsc.x - t1);
return dsc;
}
dsdbl ds_sub(dsdbl dsa, dsdbl dsb)
{
dsdbl dsc;
float e, t1, t2;
t1 = dsa.x - dsb.x;
e = t1 - dsa.x;
t2 = ((-dsb.x - e) + (dsa.x - (t1 - e))) + dsa.y - dsb.y;
dsc.x = t1 + t2;
dsc.y = t2 - (dsc.x - t1);
return dsc;
}
float ds_compare(dsdbl dsa, dsdbl dsb)
{
if (dsa.x < dsb.x) return -1.;
else if (dsa.x == dsb.x)
{
if (dsa.y < dsb.y) return -1.;
else if (dsa.y == dsb.y) return 0.;
else return 1.;
}
else return 1.;
}
dsdbl double_to_ds(double d)
{
float x = (float) d;
float y = d - (double) x;
return dsdbl { x, y };
}
int main()
{
double x = 0.0194453596504303195813267990388339967467;
double y = -1.7868687567166214869018858735216781497002;
dsdbl a = double_to_ds(x);
dsdbl b = double_to_ds(y);
dsdbl ab = ds_mul(a, b);
double xy = x * y;
std::cout << std::fixed << std::setprecision(40) << x << std::endl;
std::cout << std::fixed << std::setprecision(40) << y << std::endl;
std::cout << std::fixed << std::setprecision(40) << xy << std::endl;
std::cout << std::fixed << std::endl;
std::cout << std::fixed << std::setprecision(40) << a.x << ' ' << a.y << std::endl;
std::cout << std::fixed << std::setprecision(40) << b.x << ' ' << b.y << std::endl;
std::cout << std::fixed << std::setprecision(40) << ab.x << ' ' << ab.y << std::endl;
double abdbl = double(ab.x) + double(ab.y);
std::cout << std::endl;
std::cout << std::fixed << std::setprecision(40) << xy << std::endl;
std::cout << std::fixed << std::setprecision(40) << abdbl << std::endl;
dsdbl xyds = double_to_ds(xy);
std::cout << ds_compare(xyds, ab) << std::endl;
}
|