2.9
[glibc/nacl-glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_modfl.c
blobf2e65f0c44253d4815cfc9076957401e9596084c
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 #ifdef __STDC__
35 static const long double one = 1.0;
36 #else
37 static long double one = 1.0;
38 #endif
40 #ifdef __STDC__
41 long double __modfl(long double x, long double *iptr)
42 #else
43 long double __modfl(x, iptr)
44 long double x,*iptr;
45 #endif
47 int64_t i0,i1,j0;
48 u_int64_t i;
49 GET_LDOUBLE_WORDS64(i0,i1,x);
50 i1 &= 0x000fffffffffffffLL;
51 j0 = ((i0>>52)&0x7ff)-0x3ff; /* exponent of x */
52 if(j0<52) { /* integer part in high x */
53 if(j0<0) { /* |x|<1 */
54 /* *iptr = +-0 */
55 SET_LDOUBLE_WORDS64(*iptr,i0&0x8000000000000000ULL,0);
56 return x;
57 } else {
58 i = (0x000fffffffffffffLL)>>j0;
59 if(((i0&i)|(i1&0x7fffffffffffffffLL))==0) { /* x is integral */
60 *iptr = x;
61 /* return +-0 */
62 SET_LDOUBLE_WORDS64(x,i0&0x8000000000000000ULL,0);
63 return x;
64 } else {
65 SET_LDOUBLE_WORDS64(*iptr,i0&(~i),0);
66 return x - *iptr;
69 } else if (j0>103) { /* no fraction part */
70 *iptr = x*one;
71 /* We must handle NaNs separately. */
72 if (j0 == 0x400 && ((i0 & 0x000fffffffffffffLL) | i1))
73 return x*one;
74 /* return +-0 */
75 SET_LDOUBLE_WORDS64(x,i0&0x8000000000000000ULL,0);
76 return x;
77 } else { /* fraction part in low x */
78 i = -1ULL>>(j0-52);
79 if((i1&i)==0) { /* x is integral */
80 *iptr = x;
81 /* return +-0 */
82 SET_LDOUBLE_WORDS64(x,i0&0x8000000000000000ULL,0);
83 return x;
84 } else {
85 SET_LDOUBLE_WORDS64(*iptr,i0,i1&(~i));
86 return x - *iptr;
90 #ifdef IS_IN_libm
91 long_double_symbol (libm, __modfl, modfl);
92 #else
93 long_double_symbol (libc, __modfl, modfl);
94 #endif