4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * CDDL HEADER START
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The contents of this file are subject to the terms of the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Common Development and Distribution License (the "License").
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * You may not use this file except in compliance with the License.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * or http://www.opensolaris.org/os/licensing.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * See the License for the specific language governing permissions
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * and limitations under the License.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * When distributing Covered Code, include this CDDL HEADER in each
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * If applicable, add the following below this CDDL HEADER, with the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * fields enclosed by brackets "[]" replaced with your own identifying
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * information: Portions Copyright [yyyy] [name of copyright owner]
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * CDDL HEADER END
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Use is subject to license terms.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#pragma weak frexpf = __frexpf
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "libm.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowfloat
4bff34e37def8a90f9194d81bc345c52ba20086athurlow__frexpf(float x, int *exp) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow union {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow unsigned i;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow float f;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } xx;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow unsigned hx;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int e;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow xx.f = x;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow hx = xx.i & ~0x80000000;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (hx >= 0x7f800000) { /* x is infinite or NaN */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *exp = 0;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (x);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow e = 0;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (hx < 0x00800000) { /* x is subnormal or zero */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (hx == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *exp = 0;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (x);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* normalize x by regarding it as an integer */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow xx.f = (int) xx.i < 0 ? -(int) hx : (int) hx;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow hx = xx.i & ~0x80000000;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow e = -149;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* now xx.f is normal */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow xx.i = (xx.i & ~0x7f800000) | 0x3f000000;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *exp = e + (hx >> 23) - 0x7e;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (xx.f);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow