5 * this is big/little endian non-portable
6 * it gets the endian from the FPdbleword
15 frexp(double d, int *ep)
20 /* order matters: only isNaN can operate on NaN */
21 if(isNaN(d) || isInf(d, 0) || d == 0)
25 if((a.hi >> SHIFT) == 0){ /* normalize subnormal numbers */
26 x.x = (double)(1ULL<<SIG) * d;
29 *ep += ((x.hi >> SHIFT) & MASK) - BIAS;
30 x.hi &= ~(MASK << SHIFT);
31 x.hi |= BIAS << SHIFT;
36 ldexp(double d, int deltae)
45 e = (x.hi >> SHIFT) & MASK;
46 if(deltae >= 0 || e+deltae >= 1){ /* no underflow */
48 if(e >= MASK){ /* overflow */
53 }else{ /* underflow gracefully */
55 /* need to shift d right deltae */
56 if(e > 1){ /* shift e-1 by exponent manipulation */
60 if(deltae > 0 && e==1){ /* shift 1 by switch from 1.fff to 0.1ff */
65 z = x.hi & ((1<<SHIFT)-1);
66 x.hi &= ~((1<<SHIFT)-1);
67 x.hi |= (1<<(SHIFT-1)) | (z>>1);
69 while(deltae > 0){ /* shift bits down */
74 x.lo |= (x.hi&((1<<bits)-1)) << (32-bits);
75 z = x.hi & ((1<<SHIFT)-1);
76 x.hi &= ~((1<<SHIFT)-1);
81 x.hi &= ~(MASK << SHIFT);
82 x.hi |= (long)e << SHIFT;
87 modf(double d, double *ip)
93 e = (x.hi >> SHIFT) & MASK;
96 if(x.lo != 0 || (x.hi & 0xfffffL != 0)) /* NaN */
113 x.hi &= ~(0x1fffffL >> e);
117 x.lo &= ~(0x7fffffffL >> (e-SHIFT-2));