/*
* 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.
*/
/*
* log10l(X)
*
* Method :
* Let log10_2hi = leading 98(SPARC)/49(x86) bits of log10(2) and
* log10_2lo = log10(2) - log10_2hi,
* ivln10 = 1/log(10) rounded.
* Then
* n = ilogb(x),
* if (n<0) n = n+1;
* x = scalbn(x,-n);
* LOG10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
*
* Note1:
* For fear of destroying log10(10**n)=n, the rounding mode is
* set to Round-to-Nearest.
*
* Special cases:
* log10(x) is NaN with signal if x < 0;
* log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
* log10(NaN) is that NaN with no signal;
* log10(10**N) = N for N=0,1,...,22.
*
* Constants:
* The hexadecimal values are the intended ones for the following constants.
* The decimal values may be used, provided that the compiler will convert
* from decimal to binary accurately enough to produce the hexadecimal values
* shown.
*/
#include "libm.h"
#include "longdouble.h"
#if defined(__x86)
#endif
static const long double
#if defined(__x86)
log10_2hi = 3.010299956639811952137388947242098603469e-01L,
log10_2lo = 2.831664213089468167896664371953210945664e-31L;
#else
#endif
long double
log10l(long double x) {
long double y, z;
int n;
if (!finitel(x))
return (x + fabsl(x)); /* x is +-INF or NaN */
else if (x > zero) {
n = ilogbl(x);
if (n < 0)
n += 1;
y = n;
x = scalbnl(x, -n);
z += y * log10_2hi;
if (rd != fp_nearest)
return (z);
} else if (x == zero) /* -INF */
else /* x <0, return NaN */
}