1 /* @(#)s_modf.c 5.1 93/09/24 */
2 /* $FreeBSD: head/lib/msun/src/s_modf.c 165838 2007-01-06 21:22:38Z das $ */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
15 * modf(double x, double *iptr)
16 * return fraction part of x, and return x's integral part in *iptr.
25 #include "math_private.h"
27 static const double one = 1.0;
30 modf(double x, double *iptr)
34 EXTRACT_WORDS(i0,i1,x);
35 j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */
36 if(j0<20) { /* integer part in high x */
37 if(j0<0) { /* |x|<1 */
38 INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */
42 if(((i0&i)|i1)==0) { /* x is integral */
45 GET_HIGH_WORD(high,x);
46 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
49 INSERT_WORDS(*iptr,i0&(~i),0);
53 } else if (j0>51) { /* no fraction part */
55 if (j0 == 0x400) { /* inf/NaN */
60 GET_HIGH_WORD(high,x);
61 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
63 } else { /* fraction part in low x */
64 i = ((u_int32_t)(0xffffffff))>>(j0-20);
65 if((i1&i)==0) { /* x is integral */
68 GET_HIGH_WORD(high,x);
69 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
72 INSERT_WORDS(*iptr,i0,i1&(~i));