Commit | Line | Data |
---|---|---|
2ce81398 | 1 | #if defined(LIBC_SCCS) && !defined(lint) |
c5980113 | 2 | static char sccsid[] = "@(#)frexp.c 5.3 (Berkeley) %G%"; |
2ce81398 | 3 | #endif LIBC_SCCS and not lint |
b8f253e8 | 4 | |
c5980113 DS |
5 | #include <math.h> |
6 | ||
29aaea38 | 7 | /* |
b8f253e8 KM |
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 | */ | |
29aaea38 BJ |
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 | } | |
be56fc55 RC |
30 | if(x>=1.0) |
31 | while(x>=1.0){ | |
29aaea38 BJ |
32 | j = j+1; |
33 | x = x/2; | |
34 | } | |
be56fc55 | 35 | else if(x<0.5 && x != 0.0) |
29aaea38 BJ |
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 | } |