Update contrib.
3 * Portions Copyright (c) 1993-2005 Nokia Corporation and/or its subsidiary(-ies).
8 /* @(#)s_floor.c 5.1 93/09/24 */
10 * ====================================================
11 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
13 * Developed at SunPro, a Sun Microsystems, Inc. business.
14 * Permission to use, copy, modify, and distribute this
15 * software is freely granted, provided that this notice
17 * ====================================================
22 <<floor>>, <<floorf>>, <<ceil>>, <<ceilf>>---floor and ceiling
34 double floor(double <[x]>);
35 float floorf(float <[x]>);
36 double ceil(double <[x]>);
37 float ceilf(float <[x]>);
51 <<floor>> and <<floorf>> find
55 the nearest integer less than or equal to <[x]>.
56 <<ceil>> and <<ceilf>> find
60 the nearest integer greater than or equal to <[x]>.
63 <<floor>> and <<ceil>> return the integer result as a double.
64 <<floorf>> and <<ceilf>> return the integer result as a float.
67 <<floor>> and <<ceil>> are ANSI.
68 <<floorf>> and <<ceilf>> are extensions.
75 * Return x rounded toward -inf to integral value
79 * Inexact flag raised if x not equal to floor(x).
84 static const double huge = 1.0e300;
88 Returns the largest integer that is less than or equal to x
90 @param x Floating point value
92 EXPORT_C double floor(double x) __SOFTFP
96 EXTRACT_WORDS(i0,i1,x);
97 j0 = ((i0>>20)&0x7ff)-0x3ff;
99 if(j0<0) { /* raise inexact if x != 0 */
100 if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
102 else if(((i0&0x7fffffff)|i1)!=0)
103 { i0=0xbff00000;i1=0;}
106 i = (0x000fffff)>>j0;
107 if(((i0&i)|i1)==0) return x; /* x is integral */
108 if(huge+x>0.0) { /* raise inexact flag */
109 if(i0<0) i0 += (0x00100000)>>j0;
114 if(j0==0x400) return x+x; /* inf or NaN */
115 else return x; /* x is integral */
117 i = ((__uint32_t)(0xffffffff))>>(j0-20);
118 if((i1&i)==0) return x; /* x is integral */
119 if(huge+x>0.0) { /* raise inexact flag */
124 if(j<i1) i0 +=1 ; /* got a carry */
131 INSERT_WORDS(x,i0,i1);