Remove i486 subdirectory
[glibc.git] / sysdeps / ieee754 / dbl-64 / s_floor.c
blobbd6afa72e8cd7e0fc069dd6aac26f14fd8c2d9d2
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.
18 * Exception:
19 * Inexact flag raised if x not equal to floor(x).
22 #include <math.h>
23 #include <math_private.h>
25 static const double huge = 1.0e300;
27 double
28 __floor (double x)
30 int32_t i0, i1, j0;
31 u_int32_t i, j;
32 EXTRACT_WORDS (i0, i1, x);
33 j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
34 if (j0 < 20)
36 if (j0 < 0) /* raise inexact if x != 0 */
38 math_force_eval (huge + x); /* return 0*sign(x) if |x|<1 */
39 if (i0 >= 0)
41 i0 = i1 = 0;
43 else if (((i0 & 0x7fffffff) | i1) != 0)
45 i0 = 0xbff00000; i1 = 0;
48 else
50 i = (0x000fffff) >> j0;
51 if (((i0 & i) | i1) == 0)
52 return x; /* x is integral */
53 math_force_eval (huge + x); /* raise inexact flag */
54 if (i0 < 0)
55 i0 += (0x00100000) >> j0;
56 i0 &= (~i); i1 = 0;
59 else if (j0 > 51)
61 if (j0 == 0x400)
62 return x + x; /* inf or NaN */
63 else
64 return x; /* x is integral */
66 else
68 i = ((u_int32_t) (0xffffffff)) >> (j0 - 20);
69 if ((i1 & i) == 0)
70 return x; /* x is integral */
71 math_force_eval (huge + x); /* raise inexact flag */
72 if (i0 < 0)
74 if (j0 == 20)
75 i0 += 1;
76 else
78 j = i1 + (1 << (52 - j0));
79 if (j < i1)
80 i0 += 1; /* got a carry */
81 i1 = j;
84 i1 &= (~i);
86 INSERT_WORDS (x, i0, i1);
87 return x;
89 #ifndef __floor
90 weak_alias (__floor, floor)
91 # ifdef NO_LONG_DOUBLE
92 strong_alias (__floor, __floorl)
93 weak_alias (__floor, floorl)
94 # endif
95 #endif