]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/dbl-64/s_floor.c
1 /* Round double to integer away from zero.
2 Copyright (C) 2011-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 2011.
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 /* Based on a version which carries the following copyright: */
23 * ====================================================
24 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
26 * Developed at SunPro, a Sun Microsystems, Inc. business.
27 * Permission to use, copy, modify, and distribute this
28 * software is freely granted, provided that this notice
30 * ====================================================
33 #define NO_MATH_REDIRECT
35 #include <math_private.h>
37 #include <libm-alias-double.h>
38 #include <math-use-builtins.h>
42 * Return x rounded toward -inf to integral value
52 return __builtin_floor (x
);
54 /* Use generic implementation. */
56 EXTRACT_WORDS64 (i0
, x
);
57 int32_t j0
= ((i0
>> 52) & 0x7ff) - 0x3ff;
58 if (__glibc_likely (j0
< 52))
62 /* return 0 * sign (x) if |x| < 1 */
65 else if ((i0
& 0x7fffffffffffffffl
) != 0)
66 i0
= 0xbff0000000000000l
;
70 uint64_t i
= 0x000fffffffffffffl
>> j0
;
72 return x
; /* x is integral */
74 i0
+= 0x0010000000000000l
>> j0
;
77 INSERT_WORDS64 (x
, i0
);
80 return x
+ x
; /* inf or NaN */
82 #endif /* ! USE_FLOOR_BUILTIN */
85 libm_alias_double (__floor
, floor
)