1/* Test totalorderl and totalordermagl for ldbl-96.
2 Copyright (C) 2016-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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 <https://www.gnu.org/licenses/>. */
18
19#include <float.h>
20#include <math.h>
21#include <math_ldbl.h>
22#include <stdbool.h>
23#include <stdint.h>
24#include <stdio.h>
25
26static const uint64_t tests[] =
27 {
28 0, 1, 0x4000000000000000ULL, 0x4000000000000001ULL,
29 0x7fffffffffffffffULL
30 };
31
32static int
33do_test (void)
34{
35 int result = 0;
36
37 if (LDBL_MIN_EXP == -16382)
38 for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++)
39 {
40 long double ldx, ldy, ldnx, ldny;
41 /* Verify that the high bit of the mantissa is ignored for
42 infinities and NaNs for the M68K variant of this
43 format. */
44 SET_LDOUBLE_WORDS (ldx, 0x7fff,
45 tests[i] >> 32, tests[i] & 0xffffffffULL);
46 SET_LDOUBLE_WORDS (ldy, 0x7fff,
47 (tests[i] >> 32) | 0x80000000,
48 tests[i] & 0xffffffffULL);
49 SET_LDOUBLE_WORDS (ldnx, 0xffff,
50 tests[i] >> 32, tests[i] & 0xffffffffULL);
51 SET_LDOUBLE_WORDS (ldny, 0xffff,
52 (tests[i] >> 32) | 0x80000000,
53 tests[i] & 0xffffffffULL);
54 bool to1 = totalorderl (x: &ldx, y: &ldy);
55 bool to2 = totalorderl (x: &ldy, y: &ldx);
56 bool to3 = totalorderl (x: &ldnx, y: &ldny);
57 bool to4 = totalorderl (x: &ldny, y: &ldnx);
58 if (to1 && to2 && to3 && to4)
59 printf (format: "PASS: test %zu\n", i);
60 else
61 {
62 printf (format: "FAIL: test %zu\n", i);
63 result = 1;
64 }
65 to1 = totalordermagl (x: &ldx, y: &ldy);
66 to2 = totalordermagl (x: &ldy, y: &ldx);
67 to3 = totalordermagl (x: &ldnx, y: &ldny);
68 to4 = totalordermagl (x: &ldny, y: &ldnx);
69 if (to1 && to2 && to3 && to4)
70 printf (format: "PASS: test %zu (totalordermagl)\n", i);
71 else
72 {
73 printf (format: "FAIL: test %zu (totalordermagl)\n", i);
74 result = 1;
75 }
76 }
77
78 return result;
79}
80
81#define TEST_FUNCTION do_test ()
82#include "../test-skeleton.c"
83

source code of glibc/sysdeps/ieee754/ldbl-96/test-totalorderl-ldbl-96.c