2.9
[glibc/nacl-glibc.git] / sysdeps / ieee754 / ldbl-128 / s_modfl.c
blob63d66e7114f3df040c2abb6e92c21e9f37a7f2e9
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"
33 #ifdef __STDC__
34 static const long double one = 1.0;
35 #else
36 static long double one = 1.0;
37 #endif
39 #ifdef __STDC__
40 long double __modfl(long double x, long double *iptr)
41 #else
42 long double __modfl(x, iptr)
43 long double x,*iptr;
44 #endif
46 int64_t i0,i1,j0;
47 u_int64_t i;
48 GET_LDOUBLE_WORDS64(i0,i1,x);
49 j0 = ((i0>>48)&0x7fff)-0x3fff; /* exponent of x */
50 if(j0<48) { /* integer part in high x */
51 if(j0<0) { /* |x|<1 */
52 /* *iptr = +-0 */
53 SET_LDOUBLE_WORDS64(*iptr,i0&0x8000000000000000ULL,0);
54 return x;
55 } else {
56 i = (0x0000ffffffffffffLL)>>j0;
57 if(((i0&i)|i1)==0) { /* x is integral */
58 *iptr = x;
59 /* return +-0 */
60 SET_LDOUBLE_WORDS64(x,i0&0x8000000000000000ULL,0);
61 return x;
62 } else {
63 SET_LDOUBLE_WORDS64(*iptr,i0&(~i),0);
64 return x - *iptr;
67 } else if (j0>111) { /* no fraction part */
68 *iptr = x*one;
69 /* We must handle NaNs separately. */
70 if (j0 == 0x4000 && ((i0 & 0x0000ffffffffffffLL) | i1))
71 return x*one;
72 /* return +-0 */
73 SET_LDOUBLE_WORDS64(x,i0&0x8000000000000000ULL,0);
74 return x;
75 } else { /* fraction part in low x */
76 i = -1ULL>>(j0-48);
77 if((i1&i)==0) { /* x is integral */
78 *iptr = x;
79 /* return +-0 */
80 SET_LDOUBLE_WORDS64(x,i0&0x8000000000000000ULL,0);
81 return x;
82 } else {
83 SET_LDOUBLE_WORDS64(*iptr,i0,i1&(~i));
84 return x - *iptr;
88 weak_alias (__modfl, modfl)