Updated to fedora-glibc-20090427T1419
[glibc/history.git] / sysdeps / ieee754 / ldbl-96 / s_floorl.c
blob7115dbad9bfc478e5de860de4c2a458bd80f0294
1 /* s_floorl.c -- long double version of s_floor.c.
2 * Conversion to long double by Ulrich Drepper,
3 * Cygnus Support, drepper@cygnus.com.
4 */
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
19 #endif
22 * floorl(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 floor(x).
30 #include "math.h"
31 #include "math_private.h"
33 #ifdef __STDC__
34 static const long double huge = 1.0e4930;
35 #else
36 static long double huge = 1.0e4930;
37 #endif
39 #ifdef __STDC__
40 long double __floorl(long double x)
41 #else
42 long double __floorl(x)
43 long double x;
44 #endif
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==0) {se=0;i0=i1=0;}
55 else if(((se&0x7fff)|i0|i1)!=0)
56 { se=0xbfff;i0=i1=0;}
58 } else {
59 i = (0x7fffffff)>>j0;
60 if(((i0&i)|i1)==0) return x; /* x is integral */
61 if(huge+x>0.0) { /* raise inexact flag */
62 if(sx) {
63 if (j0>0 && (i0+(0x80000000>>j0))>i0)
64 i0 += (0x80000000)>>j0;
65 else
67 i = 0x7fffffff;
68 ++se;
71 i0 &= (~i); i1=0;
74 } else if (j0>62) {
75 if(j0==0x4000) return x+x; /* inf or NaN */
76 else return x; /* x is integral */
77 } else {
78 i = ((u_int32_t)(0xffffffff))>>(j0-31);
79 if((i1&i)==0) return x; /* x is integral */
80 if(huge+x>0.0) { /* raise inexact flag */
81 if(sx) {
82 if(j0==31) i0+=1;
83 else {
84 j = i1+(1<<(63-j0));
85 if(j<i1) i0 +=1 ; /* got a carry */
86 i1=j;
89 i1 &= (~i);
92 SET_LDOUBLE_WORDS(x,se,i0,i1);
93 return x;
95 weak_alias (__floorl, floorl)