7 # define DECIMAL_DIG 21
14 unsigned short int xs
[3] = { 0x0001, 0x0012, 0x0123 };
15 unsigned short int lxs
[7];
16 unsigned short int *xsp
;
24 /* Get the values of the internal Xi array. */
26 if (xsp
[0] != 0x330e || xsp
[1] != 0x5432 || xsp
[2] != 0x9876)
28 puts ("srand48(0x98765432) didn't set correct value");
29 printf (" expected: { %04x, %04x, %04x }\n", 0x330e, 0x5432, 0x9876);
30 printf (" seen: { %04hx, %04hx, %04hx }\n", xsp
[0], xsp
[1], xsp
[2]);
33 /* Put the values back. */
34 memcpy (xs
, xsp
, sizeof (xs
));
37 /* See whether the correct values are installed. */
41 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
42 __LINE__
- 4, 0x2fed1413l
, l
);
47 if (l
!= -0x5d73effdl
)
49 printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
50 __LINE__
- 4, -0x5d73effdl
, l
);
57 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
58 __LINE__
- 4, 0x585fcfb7l
, l
);
63 if (l
!= -0x61770b8cl
)
65 printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
66 __LINE__
- 4, -0x61770b8cl
, l
);
70 /* Test seed48. The previous call should have install the values in
71 the initialization of `xs' above. */
76 if (xsp
[0] != 0x62f2 || xsp
[1] != 0xf474 || xsp
[2] != 0x9e88)
78 puts ("seed48() did not install the values correctly");
79 printf (" expected: { %04x, %04x, %04x }\n", 0x62f2, 0xf474, 0x9e88);
80 printf (" seen: { %04hx, %04hx, %04hx }\n", xsp
[0], xsp
[1], xsp
[2]);
84 /* Test lrand48 and mrand48. We continue from the seed established
89 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
90 __LINE__
- 4, 0x017e48b5l
, l
);
95 if (l
!= -0x1485e05dl
)
97 printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
98 __LINE__
- 4, -0x1485e05dl
, l
);
103 if (l
!= 0x6b6a3f95l
)
105 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
106 __LINE__
- 4, 0x6b6a3f95l
, l
);
111 if (l
!= 0x175c0d6fl
)
113 printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
114 __LINE__
- 4, 0x175c0d6fl
, l
);
128 /* See whether the correct values are installed. */
130 if (l
!= 0x6df63d66l
)
132 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
133 __LINE__
- 4, 0x6df63d66l
, l
);
138 if (l
!= 0x2f92c8e1l
)
140 printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
141 __LINE__
- 4, 0x2f92c8e1l
, l
);
146 if (l
!= 0x3b4869ffl
)
148 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
149 __LINE__
- 4, 0x3b4869ffl
, l
);
154 if (l
!= 0x5cd4cc3el
)
156 printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
157 __LINE__
- 4, 0x5cd4cc3el
, l
);
161 /* Check whether srand48() restores the A and C parameters. */
162 srand48 (0x98765432);
164 /* See whether the correct values are installed. */
166 if (l
!= 0x2fed1413l
)
168 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
169 __LINE__
- 4, 0x2fed1413l
, l
);
174 if (l
!= -0x5d73effdl
)
176 printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
177 __LINE__
- 4, -0x5d73effdl
, l
);
182 if (l
!= 0x585fcfb7l
)
184 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
185 __LINE__
- 4, 0x585fcfb7l
, l
);
190 if (l
!= -0x61770b8cl
)
192 printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
193 __LINE__
- 4, -0x61770b8cl
, l
);
197 /* And again to see whether seed48() does the same. */
200 /* See whether lxs wasn't modified. */
202 if (l
!= 0x6df63d66l
)
204 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
205 __LINE__
- 4, 0x6df63d66l
, l
);
209 /* Test seed48. The previous call should have install the values in
210 the initialization of `xs' above. */
215 if (xsp
[0] != 0x0637 || xsp
[1] != 0x7acd || xsp
[2] != 0xdbec)
217 puts ("seed48() did not install the values correctly");
218 printf (" expected: { %04x, %04x, %04x }\n", 0x0637, 0x7acd, 0xdbec);
219 printf (" seen: { %04hx, %04hx, %04hx }\n", xsp
[0], xsp
[1], xsp
[2]);
223 /* Test lrand48 and mrand48. We continue from the seed established
226 if (l
!= 0x017e48b5l
)
228 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
229 __LINE__
- 4, 0x017e48b5l
, l
);
234 if (l
!= -0x1485e05dl
)
236 printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
237 __LINE__
- 4, -0x1485e05dl
, l
);
242 if (l
!= 0x6b6a3f95l
)
244 printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
245 __LINE__
- 4, 0x6b6a3f95l
, l
);
250 if (l
!= 0x175c0d6fl
)
252 printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
253 __LINE__
- 4, 0x175c0d6fl
, l
);
259 if (d
!= 0.0908832261858485424)
261 printf ("drand48() in line %d failed: expected %.*g, seen %.*g\n",
262 __LINE__
- 4, DECIMAL_DIG
, 0.0908832261858485424,
268 if (d
!= 0.943149381730059133133)
270 printf ("drand48() in line %d failed: expected %.*g, seen %.*g\n",
271 __LINE__
- 4, DECIMAL_DIG
, 0.943149381730059133133,
276 /* Now the functions which get the Xis passed. */
282 if (l
!= 0x1efe61a1l
)
284 printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
285 __LINE__
- 4, 0x1efe61a1l
, l
);
290 if (l
!= -0xa973860l
)
292 printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
293 __LINE__
- 4, -0xa973860l
, l
);
298 if (l
!= 0x2a5e57fel
)
300 printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
301 __LINE__
- 4, 0x2a5e57fel
, l
);
306 if (l
!= 0x71a779a8l
)
308 printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
309 __LINE__
- 4, 0x71a779a8l
, l
);
313 /* Test whether the global A and C are used. */
317 if (l
!= 0x32beee9fl
)
319 printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
320 __LINE__
- 4, 0x32beee9fl
, l
);
325 if (l
!= 0x7bddf3bal
)
327 printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
328 __LINE__
- 4, 0x7bddf3bal
, l
);
335 printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
336 __LINE__
- 4, 0x85bdf28l
, l
);
341 if (l
!= 0x7b433e47l
)
343 printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
344 __LINE__
- 4, 0x7b433e47l
, l
);
348 /* Test erand48. Also compare with the drand48 results. */
356 drand48() and erand48 in lines %d and %d produce different results\n",
357 __LINE__
- 6, __LINE__
- 5);
358 printf (" drand48() = %g, erand48() = %g\n", d
, e
);
361 else if (e
!= 0.640650904452755298735)
363 printf ("erand48() in line %d failed: expected %.*g, seen %.*g\n",
364 __LINE__
- 4, DECIMAL_DIG
, 0.640650904452755298735,
375 drand48() and erand48 in lines %d and %d produce different results\n",
376 __LINE__
- 6, __LINE__
- 5);
377 printf (" drand48() = %g, erand48() = %g\n", d
, e
);
380 else if (e
!= 0.115372323508150742555)
382 printf ("erand48() in line %d failed: expected %.*g, seen %.*g\n",
383 __LINE__
- 4, DECIMAL_DIG
, 0.0115372323508150742555,
392 #define TEST_FUNCTION do_test ()
393 #include "../test-skeleton.c"