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 = FMOD (x, y);
51 ASSERT (z >= L_(0.0));
52 ASSERT (z < y);
53 z -= x - (int) (x / y) * y;
54 ASSERT (
55 (z > - L_(16.0) / TWO_MANT_DIG
56 && z < L_(16.0) / TWO_MANT_DIG)
57 ||
58 (z > y - L_(16.0) / TWO_MANT_DIG
59 && z < y + L_(16.0) / TWO_MANT_DIG)
60 ||
61 (z > - y - L_(16.0) / TWO_MANT_DIG
62 && z < - y + 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 = FMOD (x, y);
74 DOUBLE r;
75 ASSERT (z >= L_(0.0));
76 ASSERT (z < y);
77 {
78
79
80 int q1 = (int) (x / y / L_(65536.0));
81 int q2 = (int) ((x - q1 * L_(65536.0) * y) / y);
82 DOUBLE q = (DOUBLE) q1 * L_(65536.0) + (DOUBLE) q2;
83 r = x - q * y;
84 }
85
86
87
88 z -= r;
89 ASSERT (
90 (z > - L_(2.0) * L_(1.0e9) / TWO_MANT_DIG
91 && z < L_(2.0) * L_(1.0e9) / TWO_MANT_DIG)
92 ||
93 (z > y - L_(2.0) * L_(1.0e9) / TWO_MANT_DIG
94 && z < y + L_(2.0) * L_(1.0e9) / TWO_MANT_DIG)
95 ||
96 (z > - y - L_(2.0) * L_(1.0e9) / TWO_MANT_DIG
97 && z < - y + L_(2.0) * L_(1.0e9) / TWO_MANT_DIG));
98 }
99 }
100
101 {
102 int large_exp = (MAX_EXP - 1 < 1000 ? MAX_EXP - 1 : 1000);
103 DOUBLE large = my_ldexp (L_(1.0), large_exp);
104 for (i = 0; i < SIZEOF (RANDOM) / 10; i++)
105 for (j = 0; j < SIZEOF (RANDOM) / 10; j++)
106 {
107 DOUBLE x = large * RANDOM[i];
108 DOUBLE y = RANDOM[j];
109 if (y > L_(0.0))
110 {
111 DOUBLE z = FMOD (x, y);
112
113
114 ASSERT (z >= L_(0.0));
115 ASSERT (z < y);
116 }
117 }
118 }
119 }
120
121 volatile DOUBLE x;
122 volatile DOUBLE y;
123 DOUBLE z;