1 /*
2 * Test m68k extended double denormals.
3 */
4
5 #include <stdio.h>
6 #include <stdint.h>
7
8 #define TEST(X, Y) { X, Y, X * Y }
9
10 static volatile long double test[][3] = {
11 TEST(0x1p+16383l, 0x1p-16446l),
12 TEST(0x1.1p-8223l, 0x1.1p-8224l),
13 TEST(1.0l, 0x1p-16383l),
14 };
15
16 #undef TEST
17
dump_ld(const char * label,long double ld)18 static void dump_ld(const char *label, long double ld)
19 {
20 union {
21 long double d;
22 struct {
23 uint32_t exp:16;
24 uint32_t space:16;
25 uint32_t h;
26 uint32_t l;
27 };
28 } u;
29
30 u.d = ld;
31 printf("%12s: % -27La 0x%04x 0x%08x 0x%08x\n", label, u.d, u.exp, u.h, u.l);
32 }
33
main(void)34 int main(void)
35 {
36 int i, n = sizeof(test) / sizeof(test[0]), err = 0;
37
38 for (i = 0; i < n; ++i) {
39 long double x = test[i][0];
40 long double y = test[i][1];
41 long double build_mul = test[i][2];
42 long double runtime_mul = x * y;
43
44 if (runtime_mul != build_mul) {
45 dump_ld("x", x);
46 dump_ld("y", y);
47 dump_ld("build_mul", build_mul);
48 dump_ld("runtime_mul", runtime_mul);
49 err = 1;
50 }
51 }
52 return err;
53 }
54