(__ieee754_sqrt): Remove unused variables b and n.
[kopensolaris-gnu/glibc.git] / sysdeps / ieee754 / ldbl-96 / s_ceill.c
1 /* s_ceill.c -- long double version of s_ceil.c.
2  * Conversion to long double by Ulrich Drepper,
3  * Cygnus Support, drepper@cygnus.com.
4  */
5
6 /*
7  * ====================================================
8  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9  *
10  * Developed at SunPro, a Sun Microsystems, Inc. business.
11  * Permission to use, copy, modify, and distribute this
12  * software is freely granted, provided that this notice
13  * is preserved.
14  * ====================================================
15  */
16
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
19 #endif
20
21 /*
22  * ceill(x)
23  * Return x rounded toward -inf to integral value
24  * Method:
25  *      Bit twiddling.
26  * Exception:
27  *      Inexact flag raised if x not equal to ceil(x).
28  */
29
30 #include "math.h"
31 #include "math_private.h"
32
33 #ifdef __STDC__
34 static const long double huge = 1.0e4930;
35 #else
36 static long double huge = 1.0e4930;
37 #endif
38
39 #ifdef __STDC__
40         long double __ceill(long double x)
41 #else
42         long double __ceill(x)
43         long double x;
44 #endif
45 {
46         int32_t i1,j0;
47         u_int32_t i,j,se,i0,sx;
48         GET_LDOUBLE_WORDS(se,i0,i1,x);
49         sx = (se>>15)&1;
50         j0 = (se&0x7fff)-0x3fff;
51         if(j0<31) {
52             if(j0<0) {  /* raise inexact if x != 0 */
53                 if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
54                     if(sx) {se=0x8000;i0=0;i1=0;}
55                     else if((i0|i1)!=0) { se=0x3fff;i0=0;i1=0;}
56                 }
57             } else {
58                 i = (0x7fffffff)>>j0;
59                 if(((i0&i)|i1)==0) return x; /* x is integral */
60                 if(huge+x>0.0) {        /* raise inexact flag */
61                     if(sx==0) {
62                         if (j0>0 && (i0+(0x80000000>>j0))>i0)
63                           i0+=0x80000000>>j0;
64                         else
65                           {
66                             i = 0x7fffffff;
67                             ++se;
68                           }
69                     }
70                     i0 &= (~i); i1=0;
71                 }
72             }
73         } else if (j0>62) {
74             if(j0==0x4000) return x+x;  /* inf or NaN */
75             else return x;              /* x is integral */
76         } else {
77             i = ((u_int32_t)(0xffffffff))>>(j0-31);
78             if((i1&i)==0) return x;     /* x is integral */
79             if(huge+x>0.0) {            /* raise inexact flag */
80                 if(sx==0) {
81                     if(j0==31) i0+=1;
82                     else {
83                         j = i1 + (1<<(63-j0));
84                         if(j<i1) i0+=1; /* got a carry */
85                         i1 = j;
86                     }
87                 }
88                 i1 &= (~i);
89             }
90         }
91         SET_LDOUBLE_WORDS(x,se,i0,i1);
92         return x;
93 }
94 weak_alias (__ceill, ceill)