1 /* @(#)s_floor.c 5.1 93/09/24 */
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 * ====================================================
13 #if defined(LIBM_SCCS) && !defined(lint)
14 static const char rcsid[] =
15 "$NetBSD: s_floor.c,v 1.8 1995/05/10 20:47:20 jtc Exp $";
20 * Return x rounded toward -inf to integral value
24 * Inexact flag raised if x not equal to floor(x).
27 #include "math_libm.h"
28 #include "math_private.h"
31 static const double huge_val = 1.0e300;
33 static double huge_val = 1.0e300;
36 libm_hidden_proto(floor)
38 double floor(double x)
46 EXTRACT_WORDS(i0, i1, x);
47 j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
49 if (j0 < 0) { /* raise inexact if x != 0 */
50 if (huge_val + x > 0.0) { /* return 0*sign(x) if |x|<1 */
53 } else if (((i0 & 0x7fffffff) | i1) != 0) {
59 i = (0x000fffff) >> j0;
60 if (((i0 & i) | i1) == 0)
61 return x; /* x is integral */
62 if (huge_val + x > 0.0) { /* raise inexact flag */
64 i0 += (0x00100000) >> j0;
71 return x + x; /* inf or NaN */
73 return x; /* x is integral */
75 i = ((u_int32_t) (0xffffffff)) >> (j0 - 20);
77 return x; /* x is integral */
78 if (huge_val + x > 0.0) { /* raise inexact flag */
83 j = i1 + (1 << (52 - j0));
84 if (j < (u_int32_t) i1)
85 i0 += 1; /* got a carry */
92 INSERT_WORDS(x, i0, i1);
96 libm_hidden_def(floor)