]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/ldbl-128ibm/s_totalorderl.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_totalorderl.c
1 /* Total order operation. ldbl-128ibm version.
2 Copyright (C) 2016-2018 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 <http://www.gnu.org/licenses/>. */
18
19 #include <math.h>
20 #include <math_private.h>
21 #include <nan-high-order-bit.h>
22 #include <stdint.h>
23
24 int
25 __totalorderl (long double x, long double y)
26 {
27 double xhi, xlo, yhi, ylo;
28 int64_t hx, hy, lx, ly;
29
30 ldbl_unpack (x, &xhi, &xlo);
31 EXTRACT_WORDS64 (hx, xhi);
32 ldbl_unpack (y, &yhi, &ylo);
33 EXTRACT_WORDS64 (hy, yhi);
34 #if HIGH_ORDER_BIT_IS_SET_FOR_SNAN
35 # error not implemented
36 #endif
37 uint64_t hx_sign = hx >> 63;
38 uint64_t hy_sign = hy >> 63;
39 int64_t hx_adj = hx ^ (hx_sign >> 1);
40 int64_t hy_adj = hy ^ (hy_sign >> 1);
41 if (hx_adj < hy_adj)
42 return 1;
43 else if (hx_adj > hy_adj)
44 return 0;
45
46 /* The high doubles are identical. If they are NaNs or both the low
47 parts are zero, the low parts are not significant (and if they
48 are infinities, both the low parts must be zero). */
49 if ((hx & 0x7fffffffffffffffULL) >= 0x7ff0000000000000ULL)
50 return 1;
51 EXTRACT_WORDS64 (lx, xlo);
52 EXTRACT_WORDS64 (ly, ylo);
53 if (((lx | ly) & 0x7fffffffffffffffULL) == 0)
54 return 1;
55
56 /* Otherwise compare the low parts. */
57 uint64_t lx_sign = lx >> 63;
58 uint64_t ly_sign = ly >> 63;
59 lx ^= lx_sign >> 1;
60 ly ^= ly_sign >> 1;
61 return lx <= ly;
62 }
63 weak_alias (__totalorderl, totalorderl)