1 #if defined(LIBC_SCCS) && !defined(lint) 2 static char sccsid[] = "@(#)frexp.c 5.3 (Berkeley) 02/23/91"; 3 #endif LIBC_SCCS and not lint 4 5 #include <math.h> 6 7 /* 8 * the call 9 * x = frexp(arg,&exp); 10 * must return a double fp quantity x which is <1.0 11 * and the corresponding binary exponent "exp". 12 * such that 13 * arg = x*2^exp 14 * if the argument is 0.0, return 0.0 mantissa and 0 exponent. 15 */ 16 17 double 18 frexp(x,i) 19 double x; 20 int *i; 21 { 22 int neg; 23 int j; 24 j = 0; 25 neg = 0; 26 if(x<0){ 27 x = -x; 28 neg = 1; 29 } 30 if(x>=1.0) 31 while(x>=1.0){ 32 j = j+1; 33 x = x/2; 34 } 35 else if(x<0.5 && x != 0.0) 36 while(x<0.5){ 37 j = j-1; 38 x = 2*x; 39 } 40 *i = j; 41 if(neg) x = -x; 42 return(x); 43 } 44