Add iscanonical.
[glibc.git] / sysdeps / ieee754 / ldbl-96 / test-iscanonical-ldbl-96.c
blob6827aa81087dd0000f2310f88d09112ac28e759b
1 /* Test iscanonical for ldbl-96.
2 Copyright (C) 2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <float.h>
20 #include <math.h>
21 #include <math_private.h>
22 #include <stdbool.h>
23 #include <stdint.h>
24 #include <stdio.h>
26 struct test
28 bool sign;
29 uint16_t exponent;
30 bool high;
31 uint64_t mantissa;
32 bool canonical;
35 #define M68K_VARIANT (LDBL_MIN_EXP == -16382)
37 static const struct test tests[] =
39 { false, 0, true, 0, M68K_VARIANT },
40 { true, 0, true, 0, M68K_VARIANT },
41 { false, 0, true, 1, M68K_VARIANT },
42 { true, 0, true, 1, M68K_VARIANT },
43 { false, 0, true, 0x100000000ULL, M68K_VARIANT },
44 { true, 0, true, 0x100000000ULL, M68K_VARIANT },
45 { false, 0, false, 0, true },
46 { true, 0, false, 0, true },
47 { false, 0, false, 1, true },
48 { true, 0, false, 1, true },
49 { false, 0, false, 0x100000000ULL, true },
50 { true, 0, false, 0x100000000ULL, true },
51 { false, 1, true, 0, true },
52 { true, 1, true, 0, true },
53 { false, 1, true, 1, true },
54 { true, 1, true, 1, true },
55 { false, 1, true, 0x100000000ULL, true },
56 { true, 1, true, 0x100000000ULL, true },
57 { false, 1, false, 0, false },
58 { true, 1, false, 0, false },
59 { false, 1, false, 1, false },
60 { true, 1, false, 1, false },
61 { false, 1, false, 0x100000000ULL, false },
62 { true, 1, false, 0x100000000ULL, false },
63 { false, 0x7ffe, true, 0, true },
64 { true, 0x7ffe, true, 0, true },
65 { false, 0x7ffe, true, 1, true },
66 { true, 0x7ffe, true, 1, true },
67 { false, 0x7ffe, true, 0x100000000ULL, true },
68 { true, 0x7ffe, true, 0x100000000ULL, true },
69 { false, 0x7ffe, false, 0, false },
70 { true, 0x7ffe, false, 0, false },
71 { false, 0x7ffe, false, 1, false },
72 { true, 0x7ffe, false, 1, false },
73 { false, 0x7ffe, false, 0x100000000ULL, false },
74 { true, 0x7ffe, false, 0x100000000ULL, false },
75 { false, 0x7fff, true, 0, true },
76 { true, 0x7fff, true, 0, true },
77 { false, 0x7fff, true, 1, true },
78 { true, 0x7fff, true, 1, true },
79 { false, 0x7fff, true, 0x100000000ULL, true },
80 { true, 0x7fff, true, 0x100000000ULL, true },
81 { false, 0x7fff, false, 0, M68K_VARIANT },
82 { true, 0x7fff, false, 0, M68K_VARIANT },
83 { false, 0x7fff, false, 1, M68K_VARIANT },
84 { true, 0x7fff, false, 1, M68K_VARIANT },
85 { false, 0x7fff, false, 0x100000000ULL, M68K_VARIANT },
86 { true, 0x7fff, false, 0x100000000ULL, M68K_VARIANT },
89 static int
90 do_test (void)
92 int result = 0;
94 for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++)
96 long double ld;
97 SET_LDOUBLE_WORDS (ld, tests[i].exponent | (tests[i].sign << 15),
98 (tests[i].mantissa >> 32) | (tests[i].high << 31),
99 tests[i].mantissa & 0xffffffffULL);
100 bool canonical = iscanonical (ld);
101 if (canonical == tests[i].canonical)
102 printf ("PASS: test %zu\n", i);
103 else
105 printf ("FAIL: test %zu\n", i);
106 result = 1;
110 return result;
113 #define TEST_FUNCTION do_test ()
114 #include "../test-skeleton.c"