OSDN Git Service

libm: typo fix NO_LONG_DOUBLE variant of gamma_r
[uclinux-h8/uClibc.git] / libm / s_modf.c
1 /*
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  *
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
8  * is preserved.
9  * ====================================================
10  */
11
12 /*
13  * modf(double x, double *iptr)
14  * return fraction part of x, and return x's integral part in *iptr.
15  * Method:
16  *      Bit twiddling.
17  *
18  * Exception:
19  *      No exception.
20  */
21
22 #include "math.h"
23 #include "math_private.h"
24
25 static const double one = 1.0;
26
27 double modf(double x, double *iptr)
28 {
29         int32_t i0,i1,j0;
30         u_int32_t i;
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 */
36                 return x;
37             } else {
38                 i = (0x000fffff)>>j0;
39                 if(((i0&i)|i1)==0) {            /* x is integral */
40                     u_int32_t high;
41                     *iptr = x;
42                     GET_HIGH_WORD(high,x);
43                     INSERT_WORDS(x,high&0x80000000,0);  /* return +-0 */
44                     return x;
45                 } else {
46                     INSERT_WORDS(*iptr,i0&(~i),0);
47                     return x - *iptr;
48                 }
49             }
50         } else if (j0>51) {             /* no fraction part */
51             u_int32_t high;
52             *iptr = x*one;
53             GET_HIGH_WORD(high,x);
54             INSERT_WORDS(x,high&0x80000000,0);  /* return +-0 */
55             return x;
56         } else {                        /* fraction part in low x */
57             i = ((u_int32_t)(0xffffffff))>>(j0-20);
58             if((i1&i)==0) {             /* x is integral */
59                 u_int32_t high;
60                 *iptr = x;
61                 GET_HIGH_WORD(high,x);
62                 INSERT_WORDS(x,high&0x80000000,0);      /* return +-0 */
63                 return x;
64             } else {
65                 INSERT_WORDS(*iptr,i0,i1&(~i));
66                 return x - *iptr;
67             }
68         }
69 }
70 libm_hidden_def(modf)