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.
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
13 * ====================================================
16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid
[] = "$NetBSD: $";
21 * modfq(long double x, long double *iptr)
22 * return fraction part of x, and return x's integral part in *iptr.
30 #include "quadmath-imp.h"
32 static const __float128 one
= 1.0;
34 __float128
modfq(__float128 x
, __float128
*iptr
)
38 GET_FLT128_WORDS64(i0
,i1
,x
);
39 j0
= ((i0
>>48)&0x7fff)-0x3fff; /* exponent of x */
40 if(j0
<48) { /* integer part in high x */
41 if(j0
<0) { /* |x|<1 */
43 SET_FLT128_WORDS64(*iptr
,i0
&0x8000000000000000ULL
,0);
46 i
= (0x0000ffffffffffffLL
)>>j0
;
47 if(((i0
&i
)|i1
)==0) { /* x is integral */
50 SET_FLT128_WORDS64(x
,i0
&0x8000000000000000ULL
,0);
53 SET_FLT128_WORDS64(*iptr
,i0
&(~i
),0);
57 } else if (j0
>111) { /* no fraction part */
59 /* We must handle NaNs separately. */
60 if (j0
== 0x4000 && ((i0
& 0x0000ffffffffffffLL
) | i1
))
63 SET_FLT128_WORDS64(x
,i0
&0x8000000000000000ULL
,0);
65 } else { /* fraction part in low x */
67 if((i1
&i
)==0) { /* x is integral */
70 SET_FLT128_WORDS64(x
,i0
&0x8000000000000000ULL
,0);
73 SET_FLT128_WORDS64(*iptr
,i0
,i1
&(~i
));