manual page first distributed with 4.2BSD
[unix-history] / usr / src / lib / libc / gen / frexp.c
CommitLineData
be56fc55 1/* @(#)frexp.c 4.2 (Berkeley) %G% */
29aaea38
BJ
2/*
3 the call
4 x = frexp(arg,&exp);
5 must return a double fp quantity x which is <1.0
6 and the corresponding binary exponent "exp".
7 such that
8 arg = x*2^exp
be56fc55 9 if the argument is 0.0, return 0.0 mantissa and 0 exponent.
29aaea38
BJ
10*/
11
12double
13frexp(x,i)
14double x;
15int *i;
16{
17 int neg;
18 int j;
19 j = 0;
20 neg = 0;
21 if(x<0){
22 x = -x;
23 neg = 1;
24 }
be56fc55
RC
25 if(x>=1.0)
26 while(x>=1.0){
29aaea38
BJ
27 j = j+1;
28 x = x/2;
29 }
be56fc55 30 else if(x<0.5 && x != 0.0)
29aaea38
BJ
31 while(x<0.5){
32 j = j-1;
33 x = 2*x;
34 }
35 *i = j;
36 if(neg) x = -x;
37 return(x);
38 }