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>
26 static const double one
= 1.0;
29 __modf(double x
, double *iptr
)
33 EXTRACT_WORDS64(i0
,x
);
34 j0
= ((i0
>>52)&0x7ff)-0x3ff; /* exponent of x */
35 if(j0
<52) { /* integer part in x */
36 if(j0
<0) { /* |x|<1 */
38 INSERT_WORDS64(*iptr
,i0
&UINT64_C(0x8000000000000000));
41 uint64_t i
= UINT64_C(0x000fffffffffffff)>>j0
;
42 if((i0
&i
)==0) { /* x is integral */
45 INSERT_WORDS64(x
,i0
&UINT64_C(0x8000000000000000));
48 INSERT_WORDS64(*iptr
,i0
&(~i
));
52 } else { /* no fraction part */
54 /* We must handle NaNs separately. */
55 if (j0
== 0x400 && (i0
& UINT64_C(0xfffffffffffff)))
57 INSERT_WORDS64(x
,i0
&UINT64_C(0x8000000000000000)); /* return +-0 */
61 weak_alias (__modf
, modf
)
63 strong_alias (__modf
, __modfl
)
64 weak_alias (__modf
, modfl
)