Remove powerpc, sparc fdim inlines (bug 22987).
[glibc.git] / sysdeps / ieee754 / dbl-64 / s_floor.c
blobf27c6f3ad21ac73b1bf1bd285d401ea95975b940
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 #include <math.h>
21 #include <math_private.h>
22 #include <libm-alias-double.h>
24 double
25 __floor (double x)
27 int32_t i0, i1, j0;
28 uint32_t i, j;
29 EXTRACT_WORDS (i0, i1, x);
30 j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
31 if (j0 < 20)
33 if (j0 < 0)
35 /* return 0*sign(x) if |x|<1 */
36 if (i0 >= 0)
38 i0 = i1 = 0;
40 else if (((i0 & 0x7fffffff) | i1) != 0)
42 i0 = 0xbff00000; i1 = 0;
45 else
47 i = (0x000fffff) >> j0;
48 if (((i0 & i) | i1) == 0)
49 return x; /* x is integral */
50 if (i0 < 0)
51 i0 += (0x00100000) >> j0;
52 i0 &= (~i); i1 = 0;
55 else if (j0 > 51)
57 if (j0 == 0x400)
58 return x + x; /* inf or NaN */
59 else
60 return x; /* x is integral */
62 else
64 i = ((uint32_t) (0xffffffff)) >> (j0 - 20);
65 if ((i1 & i) == 0)
66 return x; /* x is integral */
67 if (i0 < 0)
69 if (j0 == 20)
70 i0 += 1;
71 else
73 j = i1 + (1 << (52 - j0));
74 if (j < i1)
75 i0 += 1; /* got a carry */
76 i1 = j;
79 i1 &= (~i);
81 INSERT_WORDS (x, i0, i1);
82 return x;
84 #ifndef __floor
85 libm_alias_double (__floor, floor)
86 #endif