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 #define modfl _dummy_modfl 13 #include <precomp.h> 14 #undef modfl 15 16 //static const double one = 1.0; 17 18 19 20 long double modfl(long double __x, long double *__i) 21 { 22 union 23 { 24 long double* __x; 25 long_double_s* x; 26 } x; 27 union 28 { 29 long double* __i; 30 long_double_s* iptr; 31 } iptr; 32 33 int j0; 34 unsigned int i; 35 36 x.__x = &__x; 37 iptr.__i = __i; 38 39 40 j0 = x.x->exponent - 0x3fff; /* exponent of x */ 41 42 if(j0<32) { /* integer part in high x */ 43 if(j0<0) { /* |x|<1 */ 44 *__i = 0.0L; 45 iptr.iptr->sign = x.x->sign; 46 return __x; 47 } else { 48 49 i = ((unsigned int)(0xffffffff))>>(j0+1); 50 if ( x.x->mantissal == 0 && (x.x->mantissal & i) == 0 ) { 51 *__i = __x; 52 __x = 0.0L; 53 x.x->sign = iptr.iptr->sign; 54 return __x; 55 } 56 iptr.iptr->sign = x.x->sign; 57 iptr.iptr->exponent = x.x->exponent; 58 iptr.iptr->mantissah = x.x->mantissah&((~i)); 59 iptr.iptr->mantissal = 0; 60 61 return __x - *__i; 62 } 63 } else if (j0>63) { /* no fraction part */ 64 *__i = __x; 65 if ( _isnanl(__x) || _isinfl(__x) ) 66 return __x; 67 68 __x = 0.0L; 69 x.x->sign = iptr.iptr->sign; 70 return __x; 71 } else { /* fraction part in low x */ 72 73 i = ((unsigned int)(0xffffffff))>>(j0-32); 74 if ( x.x->mantissal == 0 ) { 75 *__i = __x; 76 __x = 0.0L; 77 x.x->sign = iptr.iptr->sign; 78 return __x; 79 } 80 iptr.iptr->sign = x.x->sign; 81 iptr.iptr->exponent = x.x->exponent; 82 iptr.iptr->mantissah = x.x->mantissah; 83 iptr.iptr->mantissal = x.x->mantissal&(~i); 84 85 return __x - *__i; 86 } 87 } 88