]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/ldbl-128ibm/s_iscanonicall.c
63ddb82402554f2e054f77c5a24935b45a95d71d
1 /* Test whether long double value is canonical. ldbl-128ibm version.
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/>. */
20 #include <math_private.h>
24 __iscanonicall (long double x
)
29 ldbl_unpack (x
, &xhi
, &xlo
);
30 EXTRACT_WORDS64 (hx
, xhi
);
31 EXTRACT_WORDS64 (lx
, xlo
);
32 int64_t ix
= hx
& 0x7fffffffffffffffULL
;
33 int64_t iy
= lx
& 0x7fffffffffffffffULL
;
34 int hexp
= (ix
& 0x7ff0000000000000LL
) >> 52;
35 int lexp
= (iy
& 0x7ff0000000000000LL
) >> 52;
38 /* Low part 0 is always OK. */
42 /* If a NaN, the low part does not matter. If an infinity, the
43 low part must be 0, in which case we have already returned. */
44 return ix
!= 0x7ff0000000000000LL
;
46 /* The high part is finite and the low part is nonzero. There must
47 be sufficient difference between the exponents. */
51 /* Adjust the exponent for subnormal low part. */
52 lexp
= 12 - __builtin_clzll (iy
);
53 low_p2
= iy
== (1LL << (51 + lexp
));
56 low_p2
= (iy
& 0xfffffffffffffLL
) == 0;
57 int expdiff
= hexp
- lexp
;
58 return expdiff
> 53 || (expdiff
== 53 && low_p2
&& (ix
& 1) == 0);
60 libm_hidden_def (__iscanonicall
)