1 /* Rewritten for 64-bit machines by Ulrich Drepper <drepper@gmail.com>. */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
14 * modf(double x, double *iptr)
15 * return fraction part of x, and return x's integral part in *iptr.
24 #include <math_private.h>
25 #include <libm-alias-double.h>
28 static const double one
= 1.0;
31 __modf(double x
, double *iptr
)
35 EXTRACT_WORDS64(i0
,x
);
36 j0
= ((i0
>>52)&0x7ff)-0x3ff; /* exponent of x */
37 if(j0
<52) { /* integer part in x */
38 if(j0
<0) { /* |x|<1 */
40 INSERT_WORDS64(*iptr
,i0
&UINT64_C(0x8000000000000000));
43 uint64_t i
= UINT64_C(0x000fffffffffffff)>>j0
;
44 if((i0
&i
)==0) { /* x is integral */
47 INSERT_WORDS64(x
,i0
&UINT64_C(0x8000000000000000));
50 INSERT_WORDS64(*iptr
,i0
&(~i
));
54 } else { /* no fraction part */
56 /* We must handle NaNs separately. */
57 if (j0
== 0x400 && (i0
& UINT64_C(0xfffffffffffff)))
59 INSERT_WORDS64(x
,i0
&UINT64_C(0x8000000000000000)); /* return +-0 */
64 libm_alias_double (__modf
, modf
)