Add stub sys/procfs.h file
[glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_modfl.c
blob260cc3e33ce7e63b66766af4fa36a744189edaaa
1 /* s_modfl.c -- long double version of s_modf.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 * modfl(long double x, long double *iptr)
22 * return fraction part of x, and return x's integral part in *iptr.
23 * Method:
24 * Bit twiddling.
26 * Exception:
27 * No exception.
30 #include <math.h>
31 #include <math_private.h>
32 #include <math_ldbl_opt.h>
34 static const long double one = 1.0;
36 long double __modfl(long double x, long double *iptr)
38 int64_t i0,i1,j0;
39 u_int64_t i;
40 double xhi, xlo;
42 ldbl_unpack (x, &xhi, &xlo);
43 EXTRACT_WORDS64 (i0, xhi);
44 EXTRACT_WORDS64 (i1, xlo);
45 i1 &= 0x000fffffffffffffLL;
46 j0 = ((i0>>52)&0x7ff)-0x3ff; /* exponent of x */
47 if(j0<52) { /* integer part in high x */
48 if(j0<0) { /* |x|<1 */
49 /* *iptr = +-0 */
50 INSERT_WORDS64 (xhi, i0&0x8000000000000000ULL);
51 *iptr = xhi;
52 return x;
53 } else {
54 i = (0x000fffffffffffffLL)>>j0;
55 if(((i0&i)|(i1&0x7fffffffffffffffLL))==0) { /* x is integral */
56 *iptr = x;
57 /* return +-0 */
58 INSERT_WORDS64 (xhi, i0&0x8000000000000000ULL);
59 x = xhi;
60 return x;
61 } else {
62 INSERT_WORDS64 (xhi, i0&(~i));
63 *iptr = xhi;
64 return x - *iptr;
67 } else if (j0>103) { /* no fraction part */
68 *iptr = x*one;
69 /* We must handle NaNs separately. */
70 if ((i0 & 0x7fffffffffffffffLL) > 0x7ff0000000000000LL)
71 return x*one;
72 /* return +-0 */
73 INSERT_WORDS64 (xhi, i0&0x8000000000000000ULL);
74 x = xhi;
75 return x;
76 } else { /* fraction part in low x */
77 i = -1ULL>>(j0-52);
78 if((i1&i)==0) { /* x is integral */
79 *iptr = x;
80 /* return +-0 */
81 INSERT_WORDS64 (xhi, i0&0x8000000000000000ULL);
82 x = xhi;
83 return x;
84 } else {
85 INSERT_WORDS64 (xhi, i0);
86 INSERT_WORDS64 (xlo, i1&(~i));
87 *iptr = ldbl_pack (xhi, xlo);
88 return x - *iptr;
92 #if IS_IN (libm)
93 long_double_symbol (libm, __modfl, modfl);
94 #else
95 long_double_symbol (libc, __modfl, modfl);
96 #endif