1 /* Test iscanonical and canonicalizel for ldbl-96.
2 Copyright (C) 2016-2018 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/>. */
21 #include <math_ldbl.h>
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
},
94 for (size_t i
= 0; i
< sizeof (tests
) / sizeof (tests
[0]); i
++)
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
)
103 printf ("PASS: iscanonical test %zu\n", i
);
104 long double ldc
= 12345.0L;
105 bool canonicalize_ret
= canonicalizel (&ldc
, &ld
);
106 if (canonicalize_ret
== !canonical
)
108 printf ("PASS: canonicalizel test %zu\n", i
);
111 canon_ok
= ldc
== 12345.0L;
113 canon_ok
= isnan (ldc
) && !issignaling (ldc
);
115 canon_ok
= ldc
== ld
;
117 printf ("PASS: canonicalized value test %zu\n", i
);
120 printf ("FAIL: canonicalized value test %zu\n", i
);
126 printf ("FAIL: canonicalizel test %zu\n", i
);
132 printf ("FAIL: iscanonical test %zu\n", i
);
140 #define TEST_FUNCTION do_test ()
141 #include "../test-skeleton.c"