summaryrefslogtreecommitdiffstats
path: root/lib/msun/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/msun/src')
-rw-r--r--lib/msun/src/e_log2.c60
-rw-r--r--lib/msun/src/e_log2f.c54
-rw-r--r--lib/msun/src/math.h2
-rw-r--r--lib/msun/src/math_private.h2
4 files changed, 118 insertions, 0 deletions
diff --git a/lib/msun/src/e_log2.c b/lib/msun/src/e_log2.c
new file mode 100644
index 0000000..8a729d5
--- /dev/null
+++ b/lib/msun/src/e_log2.c
@@ -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;
+}
diff --git a/lib/msun/src/e_log2f.c b/lib/msun/src/e_log2f.c
new file mode 100644
index 0000000..6b2b966
--- /dev/null
+++ b/lib/msun/src/e_log2f.c
@@ -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;
+}
diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h
index 9109727..9aa2484 100644
--- a/lib/msun/src/math.h
+++ b/lib/msun/src/math.h
@@ -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 */
diff --git a/lib/msun/src/math_private.h b/lib/msun/src/math_private.h
index 10c92f4..d79f808 100644
--- a/lib/msun/src/math_private.h
+++ b/lib/msun/src/math_private.h
@@ -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
OpenPOWER on IntegriCloud