1 /* @(#)s_modf.c 5.1 93/09/24 */
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 * ====================================================
12 * FreeBSD SVN: 165838 (2007-01-06)
16 * modf(double x, double *iptr)
17 * return fraction part of x, and return x's integral part in *iptr.
26 #include "math_private.h"
28 static const double one = 1.0;
31 modf(double x, double *iptr)
35 EXTRACT_WORDS(i0,i1,x);
36 j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */
37 if(j0<20) { /* integer part in high x */
38 if(j0<0) { /* |x|<1 */
39 INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */
43 if(((i0&i)|i1)==0) { /* x is integral */
46 GET_HIGH_WORD(high,x);
47 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
50 INSERT_WORDS(*iptr,i0&(~i),0);
54 } else if (j0>51) { /* no fraction part */
56 if (j0 == 0x400) { /* inf/NaN */
61 GET_HIGH_WORD(high,x);
62 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
64 } else { /* fraction part in low x */
65 i = ((u_int32_t)(0xffffffff))>>(j0-20);
66 if((i1&i)==0) { /* x is integral */
69 GET_HIGH_WORD(high,x);
70 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
73 INSERT_WORDS(*iptr,i0,i1&(~i));