Always use wordsize-64 version of s_rint.c.
[glibc.git] / sysdeps / ieee754 / dbl-64 / s_floor.c
blobbebc01865890e5bb999d7de593405cea3c9811fa
1 /* @(#)s_floor.c 5.1 93/09/24 */
2 /*
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
9 * is preserved.
10 * ====================================================
14 * floor(x)
15 * Return x rounded toward -inf to integral value
16 * Method:
17 * Bit twiddling.
20 #define NO_MATH_REDIRECT
21 #include <math.h>
22 #include <math_private.h>
23 #include <libm-alias-double.h>
25 double
26 __floor (double x)
28 int32_t i0, i1, j0;
29 uint32_t i, j;
30 EXTRACT_WORDS (i0, i1, x);
31 j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
32 if (j0 < 20)
34 if (j0 < 0)
36 /* return 0*sign(x) if |x|<1 */
37 if (i0 >= 0)
39 i0 = i1 = 0;
41 else if (((i0 & 0x7fffffff) | i1) != 0)
43 i0 = 0xbff00000; i1 = 0;
46 else
48 i = (0x000fffff) >> j0;
49 if (((i0 & i) | i1) == 0)
50 return x; /* x is integral */
51 if (i0 < 0)
52 i0 += (0x00100000) >> j0;
53 i0 &= (~i); i1 = 0;
56 else if (j0 > 51)
58 if (j0 == 0x400)
59 return x + x; /* inf or NaN */
60 else
61 return x; /* x is integral */
63 else
65 i = ((uint32_t) (0xffffffff)) >> (j0 - 20);
66 if ((i1 & i) == 0)
67 return x; /* x is integral */
68 if (i0 < 0)
70 if (j0 == 20)
71 i0 += 1;
72 else
74 j = i1 + (1 << (52 - j0));
75 if (j < i1)
76 i0 += 1; /* got a carry */
77 i1 = j;
80 i1 &= (~i);
82 INSERT_WORDS (x, i0, i1);
83 return x;
85 #ifndef __floor
86 libm_alias_double (__floor, floor)
87 #endif