Rules: Also build memcheck tests even when not running them
[glibc.git] / sysdeps / ieee754 / ldbl-96 / s_roundl.c
blob08b42744954caf8a0a3a24e0a576f37ef43dd974
1 /* Round long double to integer away from zero.
2 Copyright (C) 1997-2024 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 <https://www.gnu.org/licenses/>. */
19 #define NO_MATH_REDIRECT
20 #include <math.h>
22 #include <math_private.h>
23 #include <libm-alias-ldouble.h>
26 long double
27 __roundl (long double x)
29 int32_t j0;
30 uint32_t se, i1, i0;
32 GET_LDOUBLE_WORDS (se, i0, i1, x);
33 j0 = (se & 0x7fff) - 0x3fff;
34 if (j0 < 31)
36 if (j0 < 0)
38 se &= 0x8000;
39 i0 = i1 = 0;
40 if (j0 == -1)
42 se |= 0x3fff;
43 i0 = 0x80000000;
46 else
48 uint32_t i = 0x7fffffff >> j0;
49 if (((i0 & i) | i1) == 0)
50 /* X is integral. */
51 return x;
53 uint32_t j = i0 + (0x40000000 >> j0);
54 if (j < i0)
55 se += 1;
56 i0 = (j & ~i) | 0x80000000;
57 i1 = 0;
60 else if (j0 > 62)
62 if (j0 == 0x4000)
63 /* Inf or NaN. */
64 return x + x;
65 else
66 return x;
68 else
70 uint32_t i = 0xffffffff >> (j0 - 31);
71 if ((i1 & i) == 0)
72 /* X is integral. */
73 return x;
75 uint32_t j = i1 + (1 << (62 - j0));
76 if (j < i1)
78 uint32_t k = i0 + 1;
79 if (k < i0)
81 se += 1;
82 k |= 0x80000000;
84 i0 = k;
86 i1 = j;
87 i1 &= ~i;
90 SET_LDOUBLE_WORDS (x, se, i0, i1);
91 return x;
93 libm_alias_ldouble (__round, round)