frexp.c revision 1ec68d336ba97cd53f46053ac10401d16014d075
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* frexp(x, exp) returns the normalized significand of x and sets
* *exp so that x = r*2^(*exp) where r is the return value. If x
* is finite and nonzero, 1/2 <= |r| < 1.
*
* If x is zero, infinite or NaN, frexp returns x and sets *exp = 0.
* (The relevant standards do not specify *exp when x is infinite or
* NaN, but this code sets it anyway.)
*
* If x is a signaling NaN, this code returns x without attempting
* to raise the invalid operation exception. If x is subnormal,
* this code treats it as nonzero regardless of nonstandard mode.
*/
#include "libm.h"
double
union {
unsigned i[2];
double d;
double t;
unsigned hx;
int e;
xx.d = x;
*exp = 0;
return (x);
}
e = 0;
*exp = 0;
return (x);
}
/*
* normalize x by regarding it as an integer
*
* Here we use 32-bit integer arithmetic to avoid trapping
* or emulating 64-bit arithmetic. If 64-bit arithmetic is
* available (e.g., in SPARC V9), do this instead:
*
* long lx = ((long) hx << 32) | xx.i[LOWORD];
* xx.d = (xx.i[HIWORD] < 0)? -lx : lx;
*
* If subnormal arithmetic doesn't trap, just multiply x by
* a power of two.
*/
t = yy.d;
t -= yy.d; /* t = |x| scaled */
e = -1074;
}
/* now xx.d is normal */
return (xx.d);
}