Use free Windows DDK and compile with latest MinGW releases.
[reactos.git] / reactos / lib / msvcrt / math / modf.c
1 /* @(#)s_modf.c 1.3 95/01/18 */
2 /*
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 *
6 * Developed at SunSoft, 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 #include <msvcrti.h>
13
14
15 //static const double one = 1.0;
16
17 double modf(double __x, double *__i)
18 {
19 double_t * x = (double_t *)&__x;
20 double_t * iptr = ( double_t *)__i;
21
22 int j0;
23 unsigned int i;
24 j0 = x->exponent - 0x3ff; /* exponent of x */
25 if(j0<20) { /* integer part in high x */
26 if(j0<0) { /* |x|<1 */
27 *__i = 0.0;
28 iptr->sign = x->sign;
29 return __x;
30 } else {
31
32 if ( x->mantissah == 0 && x->mantissal == 0 ) {
33 *__i = __x;
34 return 0.0;
35 }
36
37 i = (0x000fffff)>>j0;
38 iptr->sign = x->sign;
39 iptr->exponent = x->exponent;
40 iptr->mantissah = x->mantissah&(~i);
41 iptr->mantissal = 0;
42 if ( __x == *__i ) {
43 __x = 0.0;
44 x->sign = iptr->sign;
45 return __x;
46 }
47 return __x - *__i;
48 }
49 } else if (j0>51) { /* no fraction part */
50 *__i = __x;
51 if ( _isnan(__x) || _isinf(__x) )
52 return __x;
53
54 __x = 0.0;
55 x->sign = iptr->sign;
56 return __x;
57 } else { /* fraction part in low x */
58
59 i = ((unsigned)(0xffffffff))>>(j0-20);
60 iptr->sign = x->sign;
61 iptr->exponent = x->exponent;
62 iptr->mantissah = x->mantissah;
63 iptr->mantissal = x->mantissal&(~i);
64 if ( __x == *__i ) {
65 __x = 0.0;
66 x->sign = iptr->sign;
67 return __x;
68 }
69 return __x - *__i;
70 }
71 }
72
73
74 long double modfl(long double __x, long double *__i)
75 {
76 long_double_t * x = (long_double_t *)&__x;
77 long_double_t * iptr = (long_double_t *)__i;
78
79 int j0;
80 unsigned int i;
81 j0 = x->exponent - 0x3fff; /* exponent of x */
82
83 if(j0<32) { /* integer part in high x */
84 if(j0<0) { /* |x|<1 */
85 *__i = 0.0L;
86 iptr->sign = x->sign;
87 return __x;
88 } else {
89
90 i = ((unsigned int)(0xffffffff))>>(j0+1);
91 if ( x->mantissal == 0 && (x->mantissal & i) == 0 ) {
92 *__i = __x;
93 __x = 0.0L;
94 x->sign = iptr->sign;
95 return __x;
96 }
97 iptr->sign = x->sign;
98 iptr->exponent = x->exponent;
99 iptr->mantissah = x->mantissah&((~i));
100 iptr->mantissal = 0;
101
102 return __x - *__i;
103 }
104 } else if (j0>63) { /* no fraction part */
105 *__i = __x;
106 if ( _isnanl(__x) || _isinfl(__x) )
107 return __x;
108
109 __x = 0.0L;
110 x->sign = iptr->sign;
111 return __x;
112 } else { /* fraction part in low x */
113
114 i = ((unsigned int)(0xffffffff))>>(j0-32);
115 if ( x->mantissal == 0 ) {
116 *__i = __x;
117 __x = 0.0L;
118 x->sign = iptr->sign;
119 return __x;
120 }
121 iptr->sign = x->sign;
122 iptr->exponent = x->exponent;
123 iptr->mantissah = x->mantissah;
124 iptr->mantissal = x->mantissal&(~i);
125
126 return __x - *__i;
127 }
128 }