date and time created 89/05/17 22:49:21 by bostic
[unix-history] / usr / src / lib / libc / gen / frexp.c
CommitLineData
2ce81398
DS
1#if defined(LIBC_SCCS) && !defined(lint)
2static char sccsid[] = "@(#)frexp.c 5.2 (Berkeley) %G%";
3#endif LIBC_SCCS and not lint
b8f253e8 4
29aaea38 5/*
b8f253e8
KM
6 * the call
7 * x = frexp(arg,&exp);
8 * must return a double fp quantity x which is <1.0
9 * and the corresponding binary exponent "exp".
10 * such that
11 * arg = x*2^exp
12 * if the argument is 0.0, return 0.0 mantissa and 0 exponent.
13 */
29aaea38
BJ
14
15double
16frexp(x,i)
17double x;
18int *i;
19{
20 int neg;
21 int j;
22 j = 0;
23 neg = 0;
24 if(x<0){
25 x = -x;
26 neg = 1;
27 }
be56fc55
RC
28 if(x>=1.0)
29 while(x>=1.0){
29aaea38
BJ
30 j = j+1;
31 x = x/2;
32 }
be56fc55 33 else if(x<0.5 && x != 0.0)
29aaea38
BJ
34 while(x<0.5){
35 j = j-1;
36 x = 2*x;
37 }
38 *i = j;
39 if(neg) x = -x;
40 return(x);
41 }