|
|
1.1 ! root 1: /* ! 2: the call ! 3: x = frexp(arg,&exp); ! 4: must return a double fp quantity x which is <1.0 ! 5: and the corresponding binary exponent "exp". ! 6: such that ! 7: arg = x*2^exp ! 8: */ ! 9: ! 10: double ! 11: frexp(x,i) ! 12: double x; ! 13: int *i; ! 14: { ! 15: int neg; ! 16: int j; ! 17: j = 0; ! 18: neg = 0; ! 19: if(x<0){ ! 20: x = -x; ! 21: neg = 1; ! 22: } ! 23: if(x>1.0) ! 24: while(x>1){ ! 25: j = j+1; ! 26: x = x/2; ! 27: } ! 28: else if(x<0.5) ! 29: while(x<0.5){ ! 30: j = j-1; ! 31: x = 2*x; ! 32: } ! 33: *i = j; ! 34: if(neg) x = -x; ! 35: return(x); ! 36: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.