]>
Commit | Line | Data |
---|---|---|
f964490f | 1 | /* Return classification value corresponding to argument. |
2b778ceb | 2 | Copyright (C) 1997-2021 Free Software Foundation, Inc. |
f964490f RM |
3 | This file is part of the GNU C Library. |
4 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and | |
350635a5 | 5 | Jakub Jelinek <jj@ultra.linux.cz>, 1999. |
f964490f RM |
6 | |
7 | The GNU C Library is free software; you can redistribute it and/or | |
8 | modify it under the terms of the GNU Lesser General Public | |
9 | License as published by the Free Software Foundation; either | |
10 | version 2.1 of the License, or (at your option) any later version. | |
11 | ||
12 | The GNU C Library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 18 | License along with the GNU C Library; if not, see |
5a82c748 | 19 | <https://www.gnu.org/licenses/>. */ |
f964490f RM |
20 | |
21 | #include <math.h> | |
22 | ||
1ed0291c | 23 | #include <math_private.h> |
f964490f RM |
24 | #include <math_ldbl_opt.h> |
25 | ||
26 | /* | |
27 | * hx lx | |
28 | * +NaN 7ffn nnnn nnnn nnnn xxxx xxxx xxxx xxxx | |
29 | * -NaN fffn nnnn nnnn nnnn xxxx xxxx xxxx xxxx | |
30 | * +Inf 7ff0 0000 0000 0000 xxxx xxxx xxxx xxxx | |
31 | * -Inf fff0 0000 0000 0000 xxxx xxxx xxxx xxxx | |
7e3706ea UD |
32 | * +0 0000 0000 0000 0000 xxxx xxxx xxxx xxxx |
33 | * -0 8000 0000 0000 0000 xxxx xxxx xxxx xxxx | |
34 | * +normal 0360 0000 0000 0000 0000 0000 0000 0000 (smallest) | |
35 | * -normal 8360 0000 0000 0000 0000 0000 0000 0000 (smallest) | |
36 | * +normal 7fef ffff ffff ffff 7c8f ffff ffff fffe (largest) | |
37 | * +normal ffef ffff ffff ffff fc8f ffff ffff fffe (largest) | |
38 | * +denorm 0360 0000 0000 0000 8000 0000 0000 0001 (largest) | |
39 | * -denorm 8360 0000 0000 0000 0000 0000 0000 0001 (largest) | |
40 | * +denorm 000n nnnn nnnn nnnn xxxx xxxx xxxx xxxx | |
41 | * -denorm 800n nnnn nnnn nnnn xxxx xxxx xxxx xxxx | |
f964490f RM |
42 | */ |
43 | ||
44 | int | |
45 | ___fpclassifyl (long double x) | |
46 | { | |
24ab7723 | 47 | uint64_t hx, lx; |
f964490f | 48 | int retval = FP_NORMAL; |
4ebd120c | 49 | double xhi, xlo; |
f964490f | 50 | |
4ebd120c AM |
51 | ldbl_unpack (x, &xhi, &xlo); |
52 | EXTRACT_WORDS64 (hx, xhi); | |
f964490f RM |
53 | if ((hx & 0x7ff0000000000000ULL) == 0x7ff0000000000000ULL) { |
54 | /* +/-NaN or +/-Inf */ | |
55 | if (hx & 0x000fffffffffffffULL) { | |
56 | /* +/-NaN */ | |
57 | retval = FP_NAN; | |
58 | } else { | |
59 | retval = FP_INFINITE; | |
60 | } | |
61 | } else { | |
62 | /* +/-zero or +/- normal or +/- denormal */ | |
63 | if (hx & 0x7fffffffffffffffULL) { | |
64 | /* +/- normal or +/- denormal */ | |
7e3706ea | 65 | if ((hx & 0x7ff0000000000000ULL) > 0x0360000000000000ULL) { |
f964490f RM |
66 | /* +/- normal */ |
67 | retval = FP_NORMAL; | |
68 | } else { | |
7e3706ea | 69 | if ((hx & 0x7ff0000000000000ULL) == 0x0360000000000000ULL) { |
4ebd120c | 70 | EXTRACT_WORDS64 (lx, xlo); |
7e3706ea UD |
71 | if ((lx & 0x7fffffffffffffff) /* lower is non-zero */ |
72 | && ((lx^hx) & 0x8000000000000000ULL)) { /* and sign differs */ | |
73 | /* +/- denormal */ | |
74 | retval = FP_SUBNORMAL; | |
75 | } else { | |
76 | /* +/- normal */ | |
77 | retval = FP_NORMAL; | |
78 | } | |
79 | } else { | |
80 | /* +/- denormal */ | |
81 | retval = FP_SUBNORMAL; | |
82 | } | |
f964490f RM |
83 | } |
84 | } else { | |
85 | /* +/- zero */ | |
86 | retval = FP_ZERO; | |
87 | } | |
88 | } | |
89 | ||
90 | return retval; | |
91 | } | |
92 | long_double_symbol (libm, ___fpclassifyl, __fpclassifyl); | |
93 | #ifdef __LONG_DOUBLE_MATH_OPTIONAL | |
94 | libm_hidden_ver (___fpclassifyl, __fpclassifyl) | |
95 | #else | |
96 | libm_hidden_def (__fpclassifyl) | |
97 | #endif |