Home | History | Annotate | Download | only in common
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 #pragma ident	"%Z%%M%	%I%	%E% SMI"  /* from UCB 5.2 3/9/86 */
     23 
     24 /*
     25  * the call
     26  *	x = frexp(arg,&exp);
     27  * must return a double fp quantity x which is <1.0
     28  * and the corresponding binary exponent "exp".
     29  * such that
     30  *	arg = x*2^exp
     31  */
     32 double
     33 frexp(x, i)
     34 	double x;
     35 	int *i;
     36 {
     37 	int neg, j;
     38 
     39 	j = 0;
     40 	neg = 0;
     41 	if (x<0) {
     42 		x = -x;
     43 		neg = 1;
     44 	}
     45 	if (x>=1.0)
     46 		while (x>=1.0) {
     47 			j = j+1;
     48 			x = x/2;
     49 		}
     50 	else if (x < 0.5 && x != 0.0)
     51 		while(x<0.5) {
     52 			j = j-1;
     53 			x = 2*x;
     54 		}
     55 	*i = j;
     56 	if(neg)
     57 		x = -x;
     58 	return (x);
     59 }
     60