This source file includes following definitions.
- my_ldexp
- test_function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 static DOUBLE
18 my_ldexp (DOUBLE x, int d)
19 {
20 for (; d > 0; d--)
21 x *= L_(2.0);
22 for (; d < 0; d++)
23 x *= L_(0.5);
24 return x;
25 }
26
27 static void
28 test_function (void)
29 {
30 int i;
31 int j;
32 const DOUBLE TWO_MANT_DIG =
33
34
35
36 (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
37 * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
38 * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
39 * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
40 * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
41
42
43 for (i = 0; i < SIZEOF (RANDOM) / 5; i++)
44 for (j = 0; j < SIZEOF (RANDOM) / 5; j++)
45 {
46 DOUBLE x = L_(16.0) * RANDOM[i];
47 DOUBLE y = RANDOM[j];
48 if (y > L_(0.0))
49 {
50 DOUBLE z = REMAINDER (x, y);
51 ASSERT (z >= - L_(0.5) * y);
52 ASSERT (z <= L_(0.5) * y);
53 z -= x - (int) ((L_(2.0) * x + y) / (L_(2.0) * y)) * y;
54 ASSERT (
55 (z > - L_(2.0) * L_(16.0) / TWO_MANT_DIG
56 && z < L_(2.0) * L_(16.0) / TWO_MANT_DIG)
57 ||
58 (z > y - L_(2.0) * L_(16.0) / TWO_MANT_DIG
59 && z < y + L_(2.0) * L_(16.0) / TWO_MANT_DIG)
60 ||
61 (z > - y - L_(2.0) * L_(16.0) / TWO_MANT_DIG
62 && z < - y + L_(2.0) * L_(16.0) / TWO_MANT_DIG));
63 }
64 }
65
66 for (i = 0; i < SIZEOF (RANDOM) / 5; i++)
67 for (j = 0; j < SIZEOF (RANDOM) / 5; j++)
68 {
69 DOUBLE x = L_(1.0e9) * RANDOM[i];
70 DOUBLE y = RANDOM[j];
71 if (y > L_(0.0))
72 {
73 DOUBLE z = REMAINDER (x, y);
74 DOUBLE r;
75 ASSERT (z >= - L_(0.5) * y);
76 ASSERT (z <= L_(0.5) * y);
77 {
78
79
80 int q1 = (int) (x / y / L_(65536.0));
81 int q2 = (int) ((L_(2.0) * (x - q1 * L_(65536.0) * y) + y)
82 / (L_(2.0) * y));
83 DOUBLE q = (DOUBLE) q1 * L_(65536.0) + (DOUBLE) q2;
84 r = x - q * y;
85 }
86
87
88
89 z -= r;
90 ASSERT (
91 (z > - L_(2.0) * L_(1.0e9) / TWO_MANT_DIG
92 && z < L_(2.0) * L_(1.0e9) / TWO_MANT_DIG)
93 ||
94 (z > y - L_(2.0) * L_(1.0e9) / TWO_MANT_DIG
95 && z < y + L_(2.0) * L_(1.0e9) / TWO_MANT_DIG)
96 ||
97 (z > - y - L_(2.0) * L_(1.0e9) / TWO_MANT_DIG
98 && z < - y + L_(2.0) * L_(1.0e9) / TWO_MANT_DIG));
99 }
100 }
101
102 {
103 int large_exp = (MAX_EXP - 1 < 1000 ? MAX_EXP - 1 : 1000);
104 DOUBLE large = my_ldexp (L_(1.0), large_exp);
105 for (i = 0; i < SIZEOF (RANDOM) / 10; i++)
106 for (j = 0; j < SIZEOF (RANDOM) / 10; j++)
107 {
108 DOUBLE x = large * RANDOM[i];
109 DOUBLE y = RANDOM[j];
110 if (y > L_(0.0))
111 {
112 DOUBLE z = REMAINDER (x, y);
113
114
115 ASSERT (z >= - L_(0.5) * y);
116 ASSERT (z <= L_(0.5) * y);
117 }
118 }
119 }
120 }
121
122 volatile DOUBLE x;
123 volatile DOUBLE y;
124 DOUBLE z;