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"
25 static const double one = 1.0;
27 double modf(double x, double *iptr)
31 EXTRACT_WORDS(i0,i1,x);
32 j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */
33 if(j0<20) { /* integer part in high x */
34 if(j0<0) { /* |x|<1 */
35 INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */
39 if(((i0&i)|i1)==0) { /* x is integral */
41 INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */
44 INSERT_WORDS(*iptr,i0&(~i),0);
48 } else if (j0>51) { /* no fraction part */
50 /* We must handle NaNs separately. */
51 if (j0 == 0x400 && ((i0 & 0xfffff) | i1))
53 INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */
55 } else { /* fraction part in low x */
56 i = ((u_int32_t)(0xffffffff))>>(j0-20);
57 if((i1&i)==0) { /* x is integral */
59 INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */
62 INSERT_WORDS(*iptr,i0,i1&(~i));