1 /* origin: FreeBSD /usr/src/lib/msun/src/s_floor.c */
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
10 * ====================================================
14 * Return x rounded toward -inf to integral value
18 * Inexact flag raised if x not equal to floor(x).
23 static const double huge = 1.0e300;
25 double floor(double x)
30 EXTRACT_WORDS(i0, i1, x);
31 // FIXME: signed shift
32 j0 = ((i0>>20)&0x7ff) - 0x3ff;
34 if (j0 < 0) { /* |x| < 1 */
35 /* raise inexact if x != 0 */
37 if (i0 >= 0) { /* x >= 0 */
39 } else if (((i0&0x7fffffff)|i1) != 0) {
47 return x; /* x is integral */
48 /* raise inexact flag */
58 return x+x; /* inf or NaN */
60 return x; /* x is integral */
62 i = (uint32_t)0xffffffff>>(j0-20);
64 return x; /* x is integral */
65 /* raise inexact flag */
73 i0++; /* got a carry */
80 INSERT_WORDS(x, i0, i1);