svn commit: r216211 - in head/lib/msun: . man src
David Schultz
das at FreeBSD.org
Sun Dec 5 22:11:22 UTC 2010
Author: das
Date: Sun Dec 5 22:11:22 2010
New Revision: 216211
URL: http://svn.freebsd.org/changeset/base/216211
Log:
Add log2() and log2f().
Added:
head/lib/msun/src/e_log2.c
- copied, changed from r216174, head/lib/msun/src/e_log10.c
head/lib/msun/src/e_log2f.c
- copied, changed from r216174, head/lib/msun/src/e_log10f.c
Modified:
head/lib/msun/Makefile
head/lib/msun/Symbol.map
head/lib/msun/man/log.3
head/lib/msun/man/math.3
head/lib/msun/src/math.h
head/lib/msun/src/math_private.h
Modified: head/lib/msun/Makefile
==============================================================================
--- head/lib/msun/Makefile Sun Dec 5 22:11:03 2010 (r216210)
+++ head/lib/msun/Makefile Sun Dec 5 22:11:22 2010 (r216211)
@@ -45,7 +45,8 @@ COMMON_SRCS= b_exp.c b_log.c b_tgamma.c
e_expf.c e_fmod.c e_fmodf.c e_gamma.c e_gamma_r.c e_gammaf.c \
e_gammaf_r.c e_hypot.c e_hypotf.c e_j0.c e_j0f.c e_j1.c e_j1f.c \
e_jn.c e_jnf.c e_lgamma.c e_lgamma_r.c e_lgammaf.c e_lgammaf_r.c \
- e_log.c e_log10.c e_log10f.c e_logf.c e_pow.c e_powf.c e_rem_pio2.c \
+ e_log.c e_log10.c e_log10f.c e_log2.c e_log2f.c e_logf.c \
+ e_pow.c e_powf.c e_rem_pio2.c \
e_rem_pio2f.c e_remainder.c e_remainderf.c e_scalb.c e_scalbf.c \
e_sinh.c e_sinhf.c e_sqrt.c e_sqrtf.c fenv.c \
k_cos.c k_cosf.c k_rem_pio2.c k_sin.c k_sinf.c \
@@ -175,7 +176,7 @@ MLINKS+=j0.3 j1.3 j0.3 jn.3 j0.3 y0.3 j0
MLINKS+=j0.3 j0f.3 j0.3 j1f.3 j0.3 jnf.3 j0.3 y0f.3 j0.3 ynf.3
MLINKS+=lgamma.3 gamma.3 lgamma.3 gammaf.3 lgamma.3 lgammaf.3 \
lgamma.3 tgamma.3 lgamma.3 tgammaf.3
-MLINKS+=log.3 log10.3 log.3 log10f.3 log.3 log1p.3 log.3 log1pf.3 log.3 logf.3
+MLINKS+=log.3 log10.3 log.3 log10f.3 log.3 log1p.3 log.3 log1pf.3 log.3 logf.3 log.3 log2.3 log.3 log2f.3
MLINKS+=lrint.3 llrint.3 lrint.3 llrintf.3 lrint.3 llrintl.3 \
lrint.3 lrintf.3 lrint.3 lrintl.3
MLINKS+=lround.3 llround.3 lround.3 llroundf.3 lround.3 llroundl.3 \
Modified: head/lib/msun/Symbol.map
==============================================================================
--- head/lib/msun/Symbol.map Sun Dec 5 22:11:03 2010 (r216210)
+++ head/lib/msun/Symbol.map Sun Dec 5 22:11:22 2010 (r216211)
@@ -222,4 +222,6 @@ FBSD_1.1 {
/* First added in 9.0-CURRENT */
FBSD_1.2 {
__isnanf;
+ log2;
+ log2f;
};
Modified: head/lib/msun/man/log.3
==============================================================================
--- head/lib/msun/man/log.3 Sun Dec 5 22:11:03 2010 (r216210)
+++ head/lib/msun/man/log.3 Sun Dec 5 22:11:22 2010 (r216211)
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2008 David Schultz <das at FreeBSD.org>
+.\" Copyright (c) 2008-2010 David Schultz <das at FreeBSD.org>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 17, 2008
+.Dd December 5, 2010
.Dt LOG 3
.Os
.Sh NAME
@@ -33,6 +33,8 @@
.Nm logl ,
.Nm log10 ,
.Nm log10f ,
+.Nm log2 ,
+.Nm log2f ,
.Nm log1p ,
.Nm log1pf
.Nd logarithm functions
@@ -49,6 +51,10 @@
.Ft float
.Fn log10f "float x"
.Ft double
+.Fn log2 "double x"
+.Ft float
+.Fn log2f "float x"
+.Ft double
.Fn log1p "double x"
.Ft float
.Fn log1pf "float x"
@@ -65,6 +71,12 @@ The
and
.Fn log10f
functions compute the logarithm base 10 of
+.Fa x ,
+while
+.Fn log2
+and
+.Fn log2f
+compute the logarithm base 2 of
.Fa x .
.Pp
The
@@ -97,6 +109,8 @@ The
.Fn logf ,
.Fn log10 ,
.Fn log10f ,
+.Fn log2 ,
+.Fn log2f ,
.Fn log1p ,
and
.Fn log1pf
Modified: head/lib/msun/man/math.3
==============================================================================
--- head/lib/msun/man/math.3 Sun Dec 5 22:11:03 2010 (r216210)
+++ head/lib/msun/man/math.3 Sun Dec 5 22:11:22 2010 (r216211)
@@ -28,7 +28,7 @@
.\" from: @(#)math.3 6.10 (Berkeley) 5/6/91
.\" $FreeBSD$
.\"
-.Dd December 16, 2007
+.Dd December 5, 2010
.Dt MATH 3
.Os
.Sh NAME
@@ -182,7 +182,7 @@ lgamma log gamma function
log natural logarithm
log10 logarithm to base 10
log1p log(1+x)
-.\" log2 base 2 logarithm
+log2 base 2 logarithm
pow exponential x**y
sin trigonometric function
sinh hyperbolic function
@@ -194,7 +194,7 @@ y1 Bessel function of the second kind of
yn Bessel function of the second kind of the order n
.El
.Pp
-Unlike the algebraic functions listed earlier, the routines
+The routines
in this section may not produce a result that is correctly rounded,
so reproducible results cannot be guaranteed across platforms.
For most of these functions, however, incorrect rounding occurs
@@ -221,18 +221,20 @@ and
values, were written for or imported into subsequent versions of FreeBSD.
.Sh BUGS
The
-.Fn log2
-function is missing, and many functions are not available in their
+.Fn cbrt
+function and many of the transcendental functions
+are not available in their
.Vt "long double"
variants.
.Pp
Many of the routines to compute transcendental functions produce
inaccurate results in other than the default rounding mode.
.Pp
-On some architectures, trigonometric argument reduction is not
-performed accurately, resulting in errors greater than 1
+On the i386 platform, trigonometric argument reduction is not
+performed accurately for very large arguments, resulting in errors
+greater than 1
.Em ulp
-for large arguments to
+for such arguments to
.Fn cos ,
.Fn sin ,
and
Copied and modified: head/lib/msun/src/e_log2.c (from r216174, head/lib/msun/src/e_log10.c)
==============================================================================
--- head/lib/msun/src/e_log10.c Sat Dec 4 02:42:52 2010 (r216174, copy source)
+++ head/lib/msun/src/e_log2.c Sun Dec 5 22:11:22 2010 (r216211)
@@ -14,54 +14,25 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-/* __ieee754_log10(x)
- * Return the base 10 logarithm of x
- *
- * Method :
- * Let log10_2hi = leading 40 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))
- *
- * Note 1:
- * To guarantee log10(10**n)=n, where 10**n is normal, the rounding
- * mode must set to Round-to-Nearest.
- * Note 2:
- * [1/log(10)] rounded to 53 bits has error .198 ulps;
- * log10 is monotonic at all binary break points.
- *
- * 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.
+/* log2(x)
+ * Return the base 2 logarithm of x.
*/
#include "math.h"
#include "math_private.h"
+#include "k_log.h"
static const double
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
-ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
-log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
-log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
+ivln2hi = 0x1.71547652000p+0,
+ivln2lo = 0x1.705fc2eefa2p-33;
static const double zero = 0.0;
double
-__ieee754_log10(double x)
+__ieee754_log2(double x)
{
- double y,z;
+ double f,hi,lo;
int32_t i,k,hx;
u_int32_t lx;
@@ -77,10 +48,13 @@ __ieee754_log10(double x)
}
if (hx >= 0x7ff00000) return x+x;
k += (hx>>20)-1023;
- i = ((u_int32_t)k&0x80000000)>>31;
- hx = (hx&0x000fffff)|((0x3ff-i)<<20);
- y = (double)(k+i);
- SET_HIGH_WORD(x,hx);
- z = y*log10_2lo + ivln10*__ieee754_log(x);
- return z+y*log10_2hi;
+ hx &= 0x000fffff;
+ i = (hx+0x95f64)&0x100000;
+ SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
+ k += (i>>20);
+ f = __kernel_log(x);
+ hi = x = x - 1;
+ SET_LOW_WORD(hi,0);
+ lo = x - hi;
+ return (x+f)*ivln2lo + (lo+f)*ivln2hi + hi*ivln2hi + k;
}
Copied and modified: head/lib/msun/src/e_log2f.c (from r216174, head/lib/msun/src/e_log10f.c)
==============================================================================
--- head/lib/msun/src/e_log10f.c Sat Dec 4 02:42:52 2010 (r216174, copy source)
+++ head/lib/msun/src/e_log2f.c Sun Dec 5 22:11:22 2010 (r216211)
@@ -1,7 +1,3 @@
-/* e_log10f.c -- float version of e_log10.c.
- * Conversion to float by Ian Lance Taylor, Cygnus Support, ian at cygnus.com.
- */
-
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
@@ -18,19 +14,19 @@ __FBSDID("$FreeBSD$");
#include "math.h"
#include "math_private.h"
+#include "k_logf.h"
static const float
two25 = 3.3554432000e+07, /* 0x4c000000 */
-ivln10 = 4.3429449201e-01, /* 0x3ede5bd9 */
-log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */
-log10_2lo = 7.9034151668e-07; /* 0x355427db */
+ivln2hi = 0x1.716p+0f,
+ivln2lo = -0x1.7135a8fa03d11p-13;
static const float zero = 0.0;
float
-__ieee754_log10f(float x)
+__ieee754_log2f(float x)
{
- float y,z;
+ float f,hi,lo;
int32_t i,k,hx;
GET_FLOAT_WORD(hx,x);
@@ -45,10 +41,14 @@ __ieee754_log10f(float x)
}
if (hx >= 0x7f800000) return x+x;
k += (hx>>23)-127;
- i = ((u_int32_t)k&0x80000000)>>31;
- hx = (hx&0x007fffff)|((0x7f-i)<<23);
- y = (float)(k+i);
- SET_FLOAT_WORD(x,hx);
- z = y*log10_2lo + ivln10*__ieee754_logf(x);
- return z+y*log10_2hi;
+ hx &= 0x007fffff;
+ i = (hx+(0x4afb0d))&0x800000;
+ SET_FLOAT_WORD(x,hx|(i^0x3f800000)); /* normalize x or x/2 */
+ k += (i>>23);
+ f = __kernel_logf(x);
+ x = x - 1;
+ GET_FLOAT_WORD(hx,x);
+ SET_FLOAT_WORD(hi,hx&0xfffff000);
+ lo = x - hi;
+ return (x+f)*ivln2lo + (lo+f)*ivln2hi + hi*ivln2hi + k;
}
Modified: head/lib/msun/src/math.h
==============================================================================
--- head/lib/msun/src/math.h Sun Dec 5 22:11:03 2010 (r216210)
+++ head/lib/msun/src/math.h Sun Dec 5 22:11:22 2010 (r216211)
@@ -236,6 +236,7 @@ double lgamma(double);
long long llrint(double);
long long llround(double);
double log1p(double);
+double log2(double);
double logb(double);
long lrint(double);
long lround(double);
@@ -319,6 +320,7 @@ int ilogbf(float) __pure2;
float ldexpf(float, int);
float log10f(float);
float log1pf(float);
+float log2f(float);
float logf(float);
float modff(float, float *); /* fundamentally !__pure2 */
Modified: head/lib/msun/src/math_private.h
==============================================================================
--- head/lib/msun/src/math_private.h Sun Dec 5 22:11:03 2010 (r216210)
+++ head/lib/msun/src/math_private.h Sun Dec 5 22:11:22 2010 (r216211)
@@ -292,6 +292,7 @@ irint(double x)
#define __ieee754_acos acos
#define __ieee754_acosh acosh
#define __ieee754_log log
+#define __ieee754_log2 log2
#define __ieee754_atanh atanh
#define __ieee754_asin asin
#define __ieee754_atan2 atan2
@@ -330,6 +331,7 @@ irint(double x)
#define __ieee754_lgammaf_r lgammaf_r
#define __ieee754_gammaf_r gammaf_r
#define __ieee754_log10f log10f
+#define __ieee754_log2f log2f
#define __ieee754_sinhf sinhf
#define __ieee754_hypotf hypotf
#define __ieee754_j0f j0f
More information about the svn-src-head
mailing list