0N/A/*
2362N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
2362N/A *
0N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2362N/A * or http://www.opensolaris.org/os/licensing.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
2362N/A
2362N/A/*
2362N/A * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
0N/A */
0N/A/*
0N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/A
0N/A#pragma weak __logb = logb
0N/A#pragma weak _logb = logb
0N/A
0N/A#include "libm.h"
0N/A#include "xpg6.h" /* __xpg6 */
0N/A#define _C99SUSv3_logb _C99SUSv3_logb_subnormal_is_like_ilogb
0N/A
0N/A#if defined(__x86)
0N/Astatic const double two52 = 4503599627370496.0;
0N/A#else
0N/A/*
2157N/A * v: high part of a non-zero subnormal |x|; w: low part of |x|
2157N/A */
2157N/Astatic int
2157N/Ailogb_subnormal(unsigned v, unsigned w) {
2157N/A int r = -1022 - 52;
2157N/A
2157N/A if (v)
2157N/A r += 32;
2157N/A else
0N/A v = w;
2157N/A if (v & 0xffff0000)
2157N/A r += 16, v >>= 16;
2157N/A if (v & 0xff00)
0N/A r += 8, v >>= 8;
0N/A if (v & 0xf0)
0N/A r += 4, v >>= 4;
0N/A v <<= 1;
return (r + ((0xffffaa50 >> v) & 0x3));
}
#endif /* defined(__x86) */
double
logb(double x) {
int *px = (int *) &x, k = px[HIWORD] & ~0x80000000;
if (k < 0x00100000) {
if ((px[LOWORD] | k) == 0)
return (_SVID_libm_err(x, x, 45));
else if ((__xpg6 & _C99SUSv3_logb) != 0) {
#if defined(__x86)
x *= two52;
return ((double) (((px[HIWORD] & 0x7ff00000) >> 20)
- 1075));
#else
return ((double) ilogb_subnormal(k, px[LOWORD]));
#endif
} else
return (-1022.0);
} else if (k < 0x7ff00000)
return ((double) ((k >> 20) - 1023));
else
return (x * x);
}