Add log2() and log2f().
This commit is contained in:
parent
e7780530fa
commit
177668d11f
@ -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_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_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_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_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 \
|
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 \
|
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.3 y1.3 j0.3 y1f.3 j0.3 yn.3
|
|||||||
MLINKS+=j0.3 j0f.3 j0.3 j1f.3 j0.3 jnf.3 j0.3 y0f.3 j0.3 ynf.3
|
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 \
|
MLINKS+=lgamma.3 gamma.3 lgamma.3 gammaf.3 lgamma.3 lgammaf.3 \
|
||||||
lgamma.3 tgamma.3 lgamma.3 tgammaf.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 \
|
MLINKS+=lrint.3 llrint.3 lrint.3 llrintf.3 lrint.3 llrintl.3 \
|
||||||
lrint.3 lrintf.3 lrint.3 lrintl.3
|
lrint.3 lrintf.3 lrint.3 lrintl.3
|
||||||
MLINKS+=lround.3 llround.3 lround.3 llroundf.3 lround.3 llroundl.3 \
|
MLINKS+=lround.3 llround.3 lround.3 llroundf.3 lround.3 llroundl.3 \
|
||||||
|
@ -222,4 +222,6 @@ FBSD_1.1 {
|
|||||||
/* First added in 9.0-CURRENT */
|
/* First added in 9.0-CURRENT */
|
||||||
FBSD_1.2 {
|
FBSD_1.2 {
|
||||||
__isnanf;
|
__isnanf;
|
||||||
|
log2;
|
||||||
|
log2f;
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
.\" Copyright (c) 2008 David Schultz <das@FreeBSD.org>
|
.\" Copyright (c) 2008-2010 David Schultz <das@FreeBSD.org>
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
@ -24,7 +24,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd January 17, 2008
|
.Dd December 5, 2010
|
||||||
.Dt LOG 3
|
.Dt LOG 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -33,6 +33,8 @@
|
|||||||
.Nm logl ,
|
.Nm logl ,
|
||||||
.Nm log10 ,
|
.Nm log10 ,
|
||||||
.Nm log10f ,
|
.Nm log10f ,
|
||||||
|
.Nm log2 ,
|
||||||
|
.Nm log2f ,
|
||||||
.Nm log1p ,
|
.Nm log1p ,
|
||||||
.Nm log1pf
|
.Nm log1pf
|
||||||
.Nd logarithm functions
|
.Nd logarithm functions
|
||||||
@ -49,6 +51,10 @@
|
|||||||
.Ft float
|
.Ft float
|
||||||
.Fn log10f "float x"
|
.Fn log10f "float x"
|
||||||
.Ft double
|
.Ft double
|
||||||
|
.Fn log2 "double x"
|
||||||
|
.Ft float
|
||||||
|
.Fn log2f "float x"
|
||||||
|
.Ft double
|
||||||
.Fn log1p "double x"
|
.Fn log1p "double x"
|
||||||
.Ft float
|
.Ft float
|
||||||
.Fn log1pf "float x"
|
.Fn log1pf "float x"
|
||||||
@ -65,6 +71,12 @@ The
|
|||||||
and
|
and
|
||||||
.Fn log10f
|
.Fn log10f
|
||||||
functions compute the logarithm base 10 of
|
functions compute the logarithm base 10 of
|
||||||
|
.Fa x ,
|
||||||
|
while
|
||||||
|
.Fn log2
|
||||||
|
and
|
||||||
|
.Fn log2f
|
||||||
|
compute the logarithm base 2 of
|
||||||
.Fa x .
|
.Fa x .
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
@ -97,6 +109,8 @@ The
|
|||||||
.Fn logf ,
|
.Fn logf ,
|
||||||
.Fn log10 ,
|
.Fn log10 ,
|
||||||
.Fn log10f ,
|
.Fn log10f ,
|
||||||
|
.Fn log2 ,
|
||||||
|
.Fn log2f ,
|
||||||
.Fn log1p ,
|
.Fn log1p ,
|
||||||
and
|
and
|
||||||
.Fn log1pf
|
.Fn log1pf
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
.\" from: @(#)math.3 6.10 (Berkeley) 5/6/91
|
.\" from: @(#)math.3 6.10 (Berkeley) 5/6/91
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd December 16, 2007
|
.Dd December 5, 2010
|
||||||
.Dt MATH 3
|
.Dt MATH 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -182,7 +182,7 @@ lgamma log gamma function
|
|||||||
log natural logarithm
|
log natural logarithm
|
||||||
log10 logarithm to base 10
|
log10 logarithm to base 10
|
||||||
log1p log(1+x)
|
log1p log(1+x)
|
||||||
.\" log2 base 2 logarithm
|
log2 base 2 logarithm
|
||||||
pow exponential x**y
|
pow exponential x**y
|
||||||
sin trigonometric function
|
sin trigonometric function
|
||||||
sinh hyperbolic function
|
sinh hyperbolic function
|
||||||
@ -194,7 +194,7 @@ y1 Bessel function of the second kind of the order 1
|
|||||||
yn Bessel function of the second kind of the order n
|
yn Bessel function of the second kind of the order n
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
Unlike the algebraic functions listed earlier, the routines
|
The routines
|
||||||
in this section may not produce a result that is correctly rounded,
|
in this section may not produce a result that is correctly rounded,
|
||||||
so reproducible results cannot be guaranteed across platforms.
|
so reproducible results cannot be guaranteed across platforms.
|
||||||
For most of these functions, however, incorrect rounding occurs
|
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.
|
values, were written for or imported into subsequent versions of FreeBSD.
|
||||||
.Sh BUGS
|
.Sh BUGS
|
||||||
The
|
The
|
||||||
.Fn log2
|
.Fn cbrt
|
||||||
function is missing, and many functions are not available in their
|
function and many of the transcendental functions
|
||||||
|
are not available in their
|
||||||
.Vt "long double"
|
.Vt "long double"
|
||||||
variants.
|
variants.
|
||||||
.Pp
|
.Pp
|
||||||
Many of the routines to compute transcendental functions produce
|
Many of the routines to compute transcendental functions produce
|
||||||
inaccurate results in other than the default rounding mode.
|
inaccurate results in other than the default rounding mode.
|
||||||
.Pp
|
.Pp
|
||||||
On some architectures, trigonometric argument reduction is not
|
On the i386 platform, trigonometric argument reduction is not
|
||||||
performed accurately, resulting in errors greater than 1
|
performed accurately for very large arguments, resulting in errors
|
||||||
|
greater than 1
|
||||||
.Em ulp
|
.Em ulp
|
||||||
for large arguments to
|
for such arguments to
|
||||||
.Fn cos ,
|
.Fn cos ,
|
||||||
.Fn sin ,
|
.Fn sin ,
|
||||||
and
|
and
|
||||||
|
60
lib/msun/src/e_log2.c
Normal file
60
lib/msun/src/e_log2.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
|
||||||
|
/* @(#)e_log10.c 1.3 95/01/18 */
|
||||||
|
/*
|
||||||
|
* ====================================================
|
||||||
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Developed at SunSoft, a Sun Microsystems, Inc. business.
|
||||||
|
* Permission to use, copy, modify, and distribute this
|
||||||
|
* software is freely granted, provided that this notice
|
||||||
|
* is preserved.
|
||||||
|
* ====================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
ivln2hi = 0x1.71547652000p+0,
|
||||||
|
ivln2lo = 0x1.705fc2eefa2p-33;
|
||||||
|
|
||||||
|
static const double zero = 0.0;
|
||||||
|
|
||||||
|
double
|
||||||
|
__ieee754_log2(double x)
|
||||||
|
{
|
||||||
|
double f,hi,lo;
|
||||||
|
int32_t i,k,hx;
|
||||||
|
u_int32_t lx;
|
||||||
|
|
||||||
|
EXTRACT_WORDS(hx,lx,x);
|
||||||
|
|
||||||
|
k=0;
|
||||||
|
if (hx < 0x00100000) { /* x < 2**-1022 */
|
||||||
|
if (((hx&0x7fffffff)|lx)==0)
|
||||||
|
return -two54/zero; /* log(+-0)=-inf */
|
||||||
|
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
|
||||||
|
k -= 54; x *= two54; /* subnormal number, scale up x */
|
||||||
|
GET_HIGH_WORD(hx,x);
|
||||||
|
}
|
||||||
|
if (hx >= 0x7ff00000) return x+x;
|
||||||
|
k += (hx>>20)-1023;
|
||||||
|
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;
|
||||||
|
}
|
54
lib/msun/src/e_log2f.c
Normal file
54
lib/msun/src/e_log2f.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* ====================================================
|
||||||
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||||
|
* Permission to use, copy, modify, and distribute this
|
||||||
|
* software is freely granted, provided that this notice
|
||||||
|
* is preserved.
|
||||||
|
* ====================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "math.h"
|
||||||
|
#include "math_private.h"
|
||||||
|
#include "k_logf.h"
|
||||||
|
|
||||||
|
static const float
|
||||||
|
two25 = 3.3554432000e+07, /* 0x4c000000 */
|
||||||
|
ivln2hi = 0x1.716p+0f,
|
||||||
|
ivln2lo = -0x1.7135a8fa03d11p-13;
|
||||||
|
|
||||||
|
static const float zero = 0.0;
|
||||||
|
|
||||||
|
float
|
||||||
|
__ieee754_log2f(float x)
|
||||||
|
{
|
||||||
|
float f,hi,lo;
|
||||||
|
int32_t i,k,hx;
|
||||||
|
|
||||||
|
GET_FLOAT_WORD(hx,x);
|
||||||
|
|
||||||
|
k=0;
|
||||||
|
if (hx < 0x00800000) { /* x < 2**-126 */
|
||||||
|
if ((hx&0x7fffffff)==0)
|
||||||
|
return -two25/zero; /* log(+-0)=-inf */
|
||||||
|
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
|
||||||
|
k -= 25; x *= two25; /* subnormal number, scale up x */
|
||||||
|
GET_FLOAT_WORD(hx,x);
|
||||||
|
}
|
||||||
|
if (hx >= 0x7f800000) return x+x;
|
||||||
|
k += (hx>>23)-127;
|
||||||
|
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;
|
||||||
|
}
|
@ -236,6 +236,7 @@ double lgamma(double);
|
|||||||
long long llrint(double);
|
long long llrint(double);
|
||||||
long long llround(double);
|
long long llround(double);
|
||||||
double log1p(double);
|
double log1p(double);
|
||||||
|
double log2(double);
|
||||||
double logb(double);
|
double logb(double);
|
||||||
long lrint(double);
|
long lrint(double);
|
||||||
long lround(double);
|
long lround(double);
|
||||||
@ -319,6 +320,7 @@ int ilogbf(float) __pure2;
|
|||||||
float ldexpf(float, int);
|
float ldexpf(float, int);
|
||||||
float log10f(float);
|
float log10f(float);
|
||||||
float log1pf(float);
|
float log1pf(float);
|
||||||
|
float log2f(float);
|
||||||
float logf(float);
|
float logf(float);
|
||||||
float modff(float, float *); /* fundamentally !__pure2 */
|
float modff(float, float *); /* fundamentally !__pure2 */
|
||||||
|
|
||||||
|
@ -292,6 +292,7 @@ irint(double x)
|
|||||||
#define __ieee754_acos acos
|
#define __ieee754_acos acos
|
||||||
#define __ieee754_acosh acosh
|
#define __ieee754_acosh acosh
|
||||||
#define __ieee754_log log
|
#define __ieee754_log log
|
||||||
|
#define __ieee754_log2 log2
|
||||||
#define __ieee754_atanh atanh
|
#define __ieee754_atanh atanh
|
||||||
#define __ieee754_asin asin
|
#define __ieee754_asin asin
|
||||||
#define __ieee754_atan2 atan2
|
#define __ieee754_atan2 atan2
|
||||||
@ -330,6 +331,7 @@ irint(double x)
|
|||||||
#define __ieee754_lgammaf_r lgammaf_r
|
#define __ieee754_lgammaf_r lgammaf_r
|
||||||
#define __ieee754_gammaf_r gammaf_r
|
#define __ieee754_gammaf_r gammaf_r
|
||||||
#define __ieee754_log10f log10f
|
#define __ieee754_log10f log10f
|
||||||
|
#define __ieee754_log2f log2f
|
||||||
#define __ieee754_sinhf sinhf
|
#define __ieee754_sinhf sinhf
|
||||||
#define __ieee754_hypotf hypotf
|
#define __ieee754_hypotf hypotf
|
||||||
#define __ieee754_j0f j0f
|
#define __ieee754_j0f j0f
|
||||||
|
Loading…
x
Reference in New Issue
Block a user