Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / msun / src / s_modf.c
1 /* @(#)s_modf.c 5.1 93/09/24 */
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
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
9  * is preserved.
10  * ====================================================
11  *
12  * $FreeBSD: src/lib/msun/src/s_modf.c,v 1.5 1999/08/28 00:06:53 peter Exp $
13  * $DragonFly: src/lib/msun/src/Attic/s_modf.c,v 1.2 2003/06/17 04:26:53 dillon Exp $
14  */
15
16 /*
17  * modf(double x, double *iptr)
18  * return fraction part of x, and return x's integral part in *iptr.
19  * Method:
20  *      Bit twiddling.
21  *
22  * Exception:
23  *      No exception.
24  */
25
26 #include "math.h"
27 #include "math_private.h"
28
29 #ifdef __STDC__
30 static const double one = 1.0;
31 #else
32 static double one = 1.0;
33 #endif
34
35 #ifdef __STDC__
36         double modf(double x, double *iptr)
37 #else
38         double modf(x, iptr)
39         double x,*iptr;
40 #endif
41 {
42         int32_t i0,i1,j0;
43         u_int32_t i;
44         EXTRACT_WORDS(i0,i1,x);
45         j0 = ((i0>>20)&0x7ff)-0x3ff;    /* exponent of x */
46         if(j0<20) {                     /* integer part in high x */
47             if(j0<0) {                  /* |x|<1 */
48                 INSERT_WORDS(*iptr,i0&0x80000000,0);    /* *iptr = +-0 */
49                 return x;
50             } else {
51                 i = (0x000fffff)>>j0;
52                 if(((i0&i)|i1)==0) {            /* x is integral */
53                     u_int32_t high;
54                     *iptr = x;
55                     GET_HIGH_WORD(high,x);
56                     INSERT_WORDS(x,high&0x80000000,0);  /* return +-0 */
57                     return x;
58                 } else {
59                     INSERT_WORDS(*iptr,i0&(~i),0);
60                     return x - *iptr;
61                 }
62             }
63         } else if (j0>51) {             /* no fraction part */
64             u_int32_t high;
65             *iptr = x*one;
66             GET_HIGH_WORD(high,x);
67             INSERT_WORDS(x,high&0x80000000,0);  /* return +-0 */
68             return x;
69         } else {                        /* fraction part in low x */
70             i = ((u_int32_t)(0xffffffff))>>(j0-20);
71             if((i1&i)==0) {             /* x is integral */
72                 u_int32_t high;
73                 *iptr = x;
74                 GET_HIGH_WORD(high,x);
75                 INSERT_WORDS(x,high&0x80000000,0);      /* return +-0 */
76                 return x;
77             } else {
78                 INSERT_WORDS(*iptr,i0,i1&(~i));
79                 return x - *iptr;
80             }
81         }
82 }