6864e52e044367529a775021b77d85c3b82e6666
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 <crtdll/float.h>
14 #include <crtdll/math.h>
15 #include <crtdll/internal/ieee.h>
19 //static const double one = 1.0;
21 double modf(double __x
, double *__i
)
24 double_t
* x
= (double_t
*)&__x
;
25 double_t
* iptr
= ( double_t
*)__i
;
29 j0
= x
->exponent
- 0x3ff; /* exponent of x */
30 if(j0
<20) { /* integer part in high x */
31 if(j0
<0) { /* |x|<1 */
37 if ( x
->mantissah
== 0 && x
->mantissal
== 0 ) {
44 iptr
->exponent
= x
->exponent
;
45 iptr
->mantissah
= x
->mantissah
&(~i
);
54 } else if (j0
>51) { /* no fraction part */
56 if ( _isnan(__x
) || _isinf(__x
) )
63 } else { /* fraction part in low x */
66 i
= ((unsigned)(0xffffffff))>>(j0
-20);
68 iptr
->exponent
= x
->exponent
;
69 iptr
->mantissah
= x
->mantissah
;
70 iptr
->mantissal
= x
->mantissal
&(~i
);
81 long double modfl(long double __x
, long double *__i
)
85 long_double_t
* x
= (long_double_t
*)&__x
;
86 long_double_t
* iptr
= (long_double_t
*)__i
;
90 j0
= x
->exponent
- 0x3fff; /* exponent of x */
93 if(j0
<32) { /* integer part in high x */
94 if(j0
<0) { /* |x|<1 */
100 i
= ((unsigned int)(0xffffffff))>>(j0
+1);
101 if ( x
->mantissal
== 0 && (x
->mantissal
& i
) == 0 ) {
104 x
->sign
= iptr
->sign
;
107 iptr
->sign
= x
->sign
;
108 iptr
->exponent
= x
->exponent
;
109 iptr
->mantissah
= x
->mantissah
&((~i
));
115 } else if (j0
>63) { /* no fraction part */
117 if ( _isnanl(__x
) || _isinfl(__x
) )
121 x
->sign
= iptr
->sign
;
123 } else { /* fraction part in low x */
125 i
= ((unsigned int)(0xffffffff))>>(j0
-32);
126 if ( x
->mantissal
== 0 ) {
129 x
->sign
= iptr
->sign
;
132 iptr
->sign
= x
->sign
;
133 iptr
->exponent
= x
->exponent
;
134 iptr
->mantissah
= x
->mantissah
;
135 iptr
->mantissal
= x
->mantissal
&(~i
);