1 /* @(#)s_modf.c 1.3 95/01/18 */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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
10 * ====================================================
13 #include <msvcrt/float.h>
14 #include <msvcrt/math.h>
15 #include <msvcrt/internal/ieee.h>
19 //static const double one = 1.0;
21 double modf(double __x
, double *__i
)
23 double_t
* x
= (double_t
*)&__x
;
24 double_t
* iptr
= ( double_t
*)__i
;
28 j0
= x
->exponent
- 0x3ff; /* exponent of x */
29 if(j0
<20) { /* integer part in high x */
30 if(j0
<0) { /* |x|<1 */
36 if ( x
->mantissah
== 0 && x
->mantissal
== 0 ) {
43 iptr
->exponent
= x
->exponent
;
44 iptr
->mantissah
= x
->mantissah
&(~i
);
53 } else if (j0
>51) { /* no fraction part */
55 if ( _isnan(__x
) || _isinf(__x
) )
61 } else { /* fraction part in low x */
63 i
= ((unsigned)(0xffffffff))>>(j0
-20);
65 iptr
->exponent
= x
->exponent
;
66 iptr
->mantissah
= x
->mantissah
;
67 iptr
->mantissal
= x
->mantissal
&(~i
);
78 long double modfl(long double __x
, long double *__i
)
80 long_double_t
* x
= (long_double_t
*)&__x
;
81 long_double_t
* iptr
= (long_double_t
*)__i
;
85 j0
= x
->exponent
- 0x3fff; /* exponent of x */
87 if(j0
<32) { /* integer part in high x */
88 if(j0
<0) { /* |x|<1 */
94 i
= ((unsigned int)(0xffffffff))>>(j0
+1);
95 if ( x
->mantissal
== 0 && (x
->mantissal
& i
) == 0 ) {
101 iptr
->sign
= x
->sign
;
102 iptr
->exponent
= x
->exponent
;
103 iptr
->mantissah
= x
->mantissah
&((~i
));
108 } else if (j0
>63) { /* no fraction part */
110 if ( _isnanl(__x
) || _isinfl(__x
) )
114 x
->sign
= iptr
->sign
;
116 } else { /* fraction part in low x */
118 i
= ((unsigned int)(0xffffffff))>>(j0
-32);
119 if ( x
->mantissal
== 0 ) {
122 x
->sign
= iptr
->sign
;
125 iptr
->sign
= x
->sign
;
126 iptr
->exponent
= x
->exponent
;
127 iptr
->mantissah
= x
->mantissah
;
128 iptr
->mantissal
= x
->mantissal
&(~i
);