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
)
37 j0
= x
.x
->exponent
- 0x3ff; /* exponent of x */
38 if(j0
<20) { /* integer part in high x */
39 if(j0
<0) { /* |x|<1 */
41 iptr
.iptr
->sign
= x
.x
->sign
;
45 if ( x
.x
->mantissah
== 0 && x
.x
->mantissal
== 0 ) {
51 iptr
.iptr
->sign
= x
.x
->sign
;
52 iptr
.iptr
->exponent
= x
.x
->exponent
;
53 iptr
.iptr
->mantissah
= x
.x
->mantissah
&(~i
);
54 iptr
.iptr
->mantissal
= 0;
57 x
.x
->sign
= iptr
.iptr
->sign
;
62 } else if (j0
>51) { /* no fraction part */
64 if ( _isnan(__x
) || _isinf(__x
) )
68 x
.x
->sign
= iptr
.iptr
->sign
;
70 } else { /* fraction part in low x */
72 i
= ((unsigned)(0xffffffff))>>(j0
-20);
73 iptr
.iptr
->sign
= x
.x
->sign
;
74 iptr
.iptr
->exponent
= x
.x
->exponent
;
75 iptr
.iptr
->mantissah
= x
.x
->mantissah
;
76 iptr
.iptr
->mantissal
= x
.x
->mantissal
&(~i
);
79 x
.x
->sign
= iptr
.iptr
->sign
;
87 long double modfl(long double __x
, long double *__i
)
107 j0
= x
.x
->exponent
- 0x3fff; /* exponent of x */
109 if(j0
<32) { /* integer part in high x */
110 if(j0
<0) { /* |x|<1 */
112 iptr
.iptr
->sign
= x
.x
->sign
;
116 i
= ((unsigned int)(0xffffffff))>>(j0
+1);
117 if ( x
.x
->mantissal
== 0 && (x
.x
->mantissal
& i
) == 0 ) {
120 x
.x
->sign
= iptr
.iptr
->sign
;
123 iptr
.iptr
->sign
= x
.x
->sign
;
124 iptr
.iptr
->exponent
= x
.x
->exponent
;
125 iptr
.iptr
->mantissah
= x
.x
->mantissah
&((~i
));
126 iptr
.iptr
->mantissal
= 0;
130 } else if (j0
>63) { /* no fraction part */
132 if ( _isnanl(__x
) || _isinfl(__x
) )
136 x
.x
->sign
= iptr
.iptr
->sign
;
138 } else { /* fraction part in low x */
140 i
= ((unsigned int)(0xffffffff))>>(j0
-32);
141 if ( x
.x
->mantissal
== 0 ) {
144 x
.x
->sign
= iptr
.iptr
->sign
;
147 iptr
.iptr
->sign
= x
.x
->sign
;
148 iptr
.iptr
->exponent
= x
.x
->exponent
;
149 iptr
.iptr
->mantissah
= x
.x
->mantissah
;
150 iptr
.iptr
->mantissal
= x
.x
->mantissal
&(~i
);