2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
9 * ====================================================
13 * modf(double x, double *iptr)
14 * return fraction part of x, and return x's integral part in *iptr.
23 #include <math_private.h>
24 #include <libm-alias-double.h>
27 static const double one
= 1.0;
30 __modf(double x
, double *iptr
)
34 EXTRACT_WORDS64(i0
,x
);
35 j0
= ((i0
>>52)&0x7ff)-0x3ff; /* exponent of x */
36 if(j0
<52) { /* integer part in x */
37 if(j0
<0) { /* |x|<1 */
39 INSERT_WORDS64(*iptr
,i0
&UINT64_C(0x8000000000000000));
42 uint64_t i
= UINT64_C(0x000fffffffffffff)>>j0
;
43 if((i0
&i
)==0) { /* x is integral */
46 INSERT_WORDS64(x
,i0
&UINT64_C(0x8000000000000000));
49 INSERT_WORDS64(*iptr
,i0
&(~i
));
53 } else { /* no fraction part */
55 /* We must handle NaNs separately. */
56 if (j0
== 0x400 && (i0
& UINT64_C(0xfffffffffffff)))
58 INSERT_WORDS64(x
,i0
&UINT64_C(0x8000000000000000)); /* return +-0 */
63 libm_alias_double (__modf
, modf
)