regression: invalid ld80 fpclassify tests
[libc-test] / src / regression / fpclassify-invalid-ld80.c
1 // commit: f657fe4b9f734d7fdea515af8dffbf7c28ce4fbc 2013-09-05
2 // classify invalid x86 ld80 representations (this is ub, we follow the fpu)
3 #include <math.h>
4 #include <float.h>
5 #include <stdint.h>
6 #include "test.h"
7
8 #if LDBL_MANT_DIG==64
9 static char *strclass(int c)
10 {
11 #define C(n) case n: return #n;
12         switch (c) {
13         C(FP_NAN)
14         C(FP_INFINITE)
15         C(FP_ZERO)
16         C(FP_SUBNORMAL)
17         C(FP_NORMAL)
18         }
19         return "invalid";
20 }
21
22 #define T(desc,got,want) do{ \
23 if (got!=want) t_error("fpclassify(%s) failed: got %s want %s\n", desc, strclass(got), #want); \
24 }while(0)
25
26 int main(void)
27 {
28         union {
29                 long double f;
30                 struct {
31                         uint64_t m;
32                         uint16_t se;
33                 } i;
34         } u;
35         int c;
36
37         u.f = 0;
38         u.i.m = (uint64_t)1<<63;
39         c = fpclassify(u.f);
40         T("zero with msb set", c, FP_NORMAL);
41         u.i.m++;
42         c = fpclassify(u.f);
43         T("subnormal with msb set", c, FP_NORMAL);
44         u.f=1;
45         u.i.m=0;
46         c = fpclassify(u.f);
47         T("normal with msb unset", c, FP_NAN);
48         u.f=INFINITY;
49         u.i.m=0;
50         c = fpclassify(u.f);
51         T("infinity with msb unset", c, FP_NAN);
52         u.f=NAN;
53         u.i.m&=(uint64_t)-1/2;
54         c = fpclassify(u.f);
55         T("nan with msb unset", c, FP_NAN);
56         return t_status;
57 }
58 #else
59 int main(void)
60 {
61         return 0;
62 }
63 #endif