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 * ====================================================
15 //static const double one = 1.0;
17 double modf(double __x
, double *__i
)
19 double_t
* x
= (double_t
*)&__x
;
20 double_t
* iptr
= ( double_t
*)__i
;
24 j0
= x
->exponent
- 0x3ff; /* exponent of x */
25 if(j0
<20) { /* integer part in high x */
26 if(j0
<0) { /* |x|<1 */
32 if ( x
->mantissah
== 0 && x
->mantissal
== 0 ) {
39 iptr
->exponent
= x
->exponent
;
40 iptr
->mantissah
= x
->mantissah
&(~i
);
49 } else if (j0
>51) { /* no fraction part */
51 if ( _isnan(__x
) || _isinf(__x
) )
57 } else { /* fraction part in low x */
59 i
= ((unsigned)(0xffffffff))>>(j0
-20);
61 iptr
->exponent
= x
->exponent
;
62 iptr
->mantissah
= x
->mantissah
;
63 iptr
->mantissal
= x
->mantissal
&(~i
);
74 long double modfl(long double __x
, long double *__i
)
76 long_double_t
* x
= (long_double_t
*)&__x
;
77 long_double_t
* iptr
= (long_double_t
*)__i
;
81 j0
= x
->exponent
- 0x3fff; /* exponent of x */
83 if(j0
<32) { /* integer part in high x */
84 if(j0
<0) { /* |x|<1 */
90 i
= ((unsigned int)(0xffffffff))>>(j0
+1);
91 if ( x
->mantissal
== 0 && (x
->mantissal
& i
) == 0 ) {
98 iptr
->exponent
= x
->exponent
;
99 iptr
->mantissah
= x
->mantissah
&((~i
));
104 } else if (j0
>63) { /* no fraction part */
106 if ( _isnanl(__x
) || _isinfl(__x
) )
110 x
->sign
= iptr
->sign
;
112 } else { /* fraction part in low x */
114 i
= ((unsigned int)(0xffffffff))>>(j0
-32);
115 if ( x
->mantissal
== 0 ) {
118 x
->sign
= iptr
->sign
;
121 iptr
->sign
= x
->sign
;
122 iptr
->exponent
= x
->exponent
;
123 iptr
->mantissah
= x
->mantissah
;
124 iptr
->mantissal
= x
->mantissal
&(~i
);