Fix spurious UNAVAIL status is getaddrinfo
[glibc.git] / sysdeps / ieee754 / ldbl-128 / s_floorl.c
blob2a60a79fc50e1ea2eeb44e9be67b3c877aaa6cba
1 /* s_floorl.c -- long double version of s_floor.c.
2 * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
3 */
5 /*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid[] = "$NetBSD: $";
18 #endif
21 * floorl(x)
22 * Return x rounded toward -inf to integral value
23 * Method:
24 * Bit twiddling.
25 * Exception:
26 * Inexact flag raised if x not equal to floor(x).
29 #include "math.h"
30 #include "math_private.h"
32 #ifdef __STDC__
33 static const long double huge = 1.0e4930L;
34 #else
35 static long double huge = 1.0e4930L;
36 #endif
38 #ifdef __STDC__
39 long double __floorl(long double x)
40 #else
41 long double __floorl(x)
42 long double x;
43 #endif
45 int64_t i0,i1,j0;
46 u_int64_t i,j;
47 GET_LDOUBLE_WORDS64(i0,i1,x);
48 j0 = ((i0>>48)&0x7fff)-0x3fff;
49 if(j0<48) {
50 if(j0<0) { /* raise inexact if x != 0 */
51 if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
52 if(i0>=0) {i0=i1=0;}
53 else if(((i0&0x7fffffffffffffffLL)|i1)!=0)
54 { i0=0xbfff000000000000ULL;i1=0;}
56 } else {
57 i = (0x0000ffffffffffffULL)>>j0;
58 if(((i0&i)|i1)==0) return x; /* x is integral */
59 if(huge+x>0.0) { /* raise inexact flag */
60 if(i0<0) i0 += (0x0001000000000000LL)>>j0;
61 i0 &= (~i); i1=0;
64 } else if (j0>111) {
65 if(j0==0x4000) return x+x; /* inf or NaN */
66 else return x; /* x is integral */
67 } else {
68 i = -1ULL>>(j0-48);
69 if((i1&i)==0) return x; /* x is integral */
70 if(huge+x>0.0) { /* raise inexact flag */
71 if(i0<0) {
72 if(j0==48) i0+=1;
73 else {
74 j = i1+(1LL<<(112-j0));
75 if(j<i1) i0 +=1 ; /* got a carry */
76 i1=j;
79 i1 &= (~i);
82 SET_LDOUBLE_WORDS64(x,i0,i1);
83 return x;
85 weak_alias (__floorl, floorl)