]>
Commit | Line | Data |
---|---|---|
f964490f RM |
1 | /* Truncate (toward zero) long double floating-point values. |
2 | IBM extended format long double version. | |
6d7e8eda | 3 | Copyright (C) 2006-2023 Free Software Foundation, Inc. |
f964490f RM |
4 | This file is part of the GNU C Library. |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
f964490f | 19 | |
7abf97be | 20 | #define NO_MATH_REDIRECT |
f964490f | 21 | #include <math.h> |
0d13dfa1 | 22 | #include <math_private.h> |
f964490f RM |
23 | #include <math_ldbl_opt.h> |
24 | #include <float.h> | |
25 | #include <ieee754.h> | |
26 | ||
7abf97be JM |
27 | double ceil (double) asm ("__ceil"); |
28 | double floor (double) asm ("__floor"); | |
29 | double trunc (double) asm ("__trunc"); | |
30 | ||
f964490f | 31 | |
f964490f RM |
32 | long double |
33 | __truncl (long double x) | |
f964490f | 34 | { |
5c68d401 | 35 | double xh, xl, hi, lo; |
f964490f | 36 | |
5c68d401 | 37 | ldbl_unpack (x, &xh, &xl); |
f964490f | 38 | |
5c68d401 RM |
39 | /* Return Inf, Nan, +/-0 unchanged. */ |
40 | if (__builtin_expect (xh != 0.0 | |
41 | && __builtin_isless (__builtin_fabs (xh), | |
42 | __builtin_inf ()), 1)) | |
f964490f | 43 | { |
7abf97be | 44 | hi = trunc (xh); |
e2310a27 | 45 | if (hi != xh) |
f964490f | 46 | { |
e2310a27 JM |
47 | /* The high part is not an integer; the low part does not |
48 | affect the result. */ | |
49 | xh = hi; | |
50 | xl = 0; | |
f964490f | 51 | } |
5c68d401 | 52 | else |
f964490f | 53 | { |
e2310a27 | 54 | /* The high part is a nonzero integer. */ |
71223ef9 | 55 | lo = xh > 0 ? floor (xl) : ceil (xl); |
e2310a27 JM |
56 | xh = hi; |
57 | xl = lo; | |
58 | ldbl_canonicalize_int (&xh, &xl); | |
f964490f | 59 | } |
f964490f | 60 | } |
bba14195 JM |
61 | else |
62 | /* Quiet signaling NaN arguments. */ | |
63 | xh += xh; | |
f964490f | 64 | |
5c68d401 | 65 | return ldbl_pack (xh, xl); |
f964490f RM |
66 | } |
67 | ||
68 | long_double_symbol (libm, __truncl, truncl); |