aboutsummaryrefslogtreecommitdiff
path: root/newlib/libm/common
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2009-03-18 18:11:18 +0000
committerJeff Johnston <jjohnstn@redhat.com>2009-03-18 18:11:18 +0000
commitd57ff5a8acdd5653394aa6b3b688990f486d95d6 (patch)
tree7082101a893df4a65c0b6b6b7e2c15a808c5708f /newlib/libm/common
parent2db87fe669aa7ff69ddffcea32b9cb38124ae480 (diff)
downloadnewlib-d57ff5a8acdd5653394aa6b3b688990f486d95d6.zip
newlib-d57ff5a8acdd5653394aa6b3b688990f486d95d6.tar.gz
newlib-d57ff5a8acdd5653394aa6b3b688990f486d95d6.tar.bz2
2009-03-18 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
* libm/common/s_log2.c: New file. * libm/common/sf_log2.c: Ditto. * libm/common/Makefile.am: Add s_log2.c and sf_log2.c. * libm/common/Makefile.in: Regenerated. * libc/include/math.h: Add log2 and log2f function prototypes.
Diffstat (limited to 'newlib/libm/common')
-rw-r--r--newlib/libm/common/Makefile.am8
-rw-r--r--newlib/libm/common/Makefile.in62
-rw-r--r--newlib/libm/common/s_log2.c73
-rw-r--r--newlib/libm/common/sf_log2.c48
4 files changed, 166 insertions, 25 deletions
diff --git a/newlib/libm/common/Makefile.am b/newlib/libm/common/Makefile.am
index f79a67c..1369c25 100644
--- a/newlib/libm/common/Makefile.am
+++ b/newlib/libm/common/Makefile.am
@@ -8,7 +8,7 @@ src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \
s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c s_infconst.c \
s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
- s_rint.c s_logb.c s_matherr.c s_lib_ver.c \
+ s_rint.c s_logb.c s_log2.c s_matherr.c s_lib_ver.c \
s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c s_lrint.c \
s_lround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
s_signbit.c s_trunc.c
@@ -17,7 +17,7 @@ fsrc = sf_finite.c sf_copysign.c sf_modf.c sf_scalbn.c \
sf_cbrt.c sf_exp10.c sf_expm1.c sf_ilogb.c \
sf_infinity.c sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c \
sf_log1p.c sf_nan.c sf_nextafter.c sf_pow10.c \
- sf_rint.c sf_logb.c \
+ sf_rint.c sf_logb.c sf_log2.c \
sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_fpclassify.c sf_lrint.c \
sf_lround.c sf_nearbyint.c sf_remquo.c sf_round.c \
sf_scalbln.c sf_trunc.c
@@ -94,6 +94,10 @@ slog1p.def: s_log1p.c
$(CHEW) < $(srcdir)/s_log1p.c >$@ 2>/dev/null
touch stmp-def
+slog2.def: s_log2.c
+ $(CHEW) < $(srcdir)/s_log2.c >$@ 2>/dev/null
+ touch stmp-def
+
smodf.def: s_modf.c
$(CHEW) < $(srcdir)/s_modf.c >$@ 2>/dev/null
touch stmp-def
diff --git a/newlib/libm/common/Makefile.in b/newlib/libm/common/Makefile.in
index 498b3f3..f84166c 100644
--- a/newlib/libm/common/Makefile.in
+++ b/newlib/libm/common/Makefile.in
@@ -67,14 +67,14 @@ am__objects_1 = lib_a-s_finite.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \
lib_a-s_log1p.$(OBJEXT) lib_a-s_nan.$(OBJEXT) \
lib_a-s_nextafter.$(OBJEXT) lib_a-s_pow10.$(OBJEXT) \
lib_a-s_rint.$(OBJEXT) lib_a-s_logb.$(OBJEXT) \
- lib_a-s_matherr.$(OBJEXT) lib_a-s_lib_ver.$(OBJEXT) \
- lib_a-s_fdim.$(OBJEXT) lib_a-s_fma.$(OBJEXT) \
- lib_a-s_fmax.$(OBJEXT) lib_a-s_fmin.$(OBJEXT) \
- lib_a-s_fpclassify.$(OBJEXT) lib_a-s_lrint.$(OBJEXT) \
- lib_a-s_lround.$(OBJEXT) lib_a-s_nearbyint.$(OBJEXT) \
- lib_a-s_remquo.$(OBJEXT) lib_a-s_round.$(OBJEXT) \
- lib_a-s_scalbln.$(OBJEXT) lib_a-s_signbit.$(OBJEXT) \
- lib_a-s_trunc.$(OBJEXT)
+ lib_a-s_log2.$(OBJEXT) lib_a-s_matherr.$(OBJEXT) \
+ lib_a-s_lib_ver.$(OBJEXT) lib_a-s_fdim.$(OBJEXT) \
+ lib_a-s_fma.$(OBJEXT) lib_a-s_fmax.$(OBJEXT) \
+ lib_a-s_fmin.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \
+ lib_a-s_lrint.$(OBJEXT) lib_a-s_lround.$(OBJEXT) \
+ lib_a-s_nearbyint.$(OBJEXT) lib_a-s_remquo.$(OBJEXT) \
+ lib_a-s_round.$(OBJEXT) lib_a-s_scalbln.$(OBJEXT) \
+ lib_a-s_signbit.$(OBJEXT) lib_a-s_trunc.$(OBJEXT)
am__objects_2 = lib_a-sf_finite.$(OBJEXT) lib_a-sf_copysign.$(OBJEXT) \
lib_a-sf_modf.$(OBJEXT) lib_a-sf_scalbn.$(OBJEXT) \
lib_a-sf_cbrt.$(OBJEXT) lib_a-sf_exp10.$(OBJEXT) \
@@ -84,13 +84,13 @@ am__objects_2 = lib_a-sf_finite.$(OBJEXT) lib_a-sf_copysign.$(OBJEXT) \
lib_a-sf_isnanf.$(OBJEXT) lib_a-sf_log1p.$(OBJEXT) \
lib_a-sf_nan.$(OBJEXT) lib_a-sf_nextafter.$(OBJEXT) \
lib_a-sf_pow10.$(OBJEXT) lib_a-sf_rint.$(OBJEXT) \
- lib_a-sf_logb.$(OBJEXT) lib_a-sf_fdim.$(OBJEXT) \
- lib_a-sf_fma.$(OBJEXT) lib_a-sf_fmax.$(OBJEXT) \
- lib_a-sf_fmin.$(OBJEXT) lib_a-sf_fpclassify.$(OBJEXT) \
- lib_a-sf_lrint.$(OBJEXT) lib_a-sf_lround.$(OBJEXT) \
- lib_a-sf_nearbyint.$(OBJEXT) lib_a-sf_remquo.$(OBJEXT) \
- lib_a-sf_round.$(OBJEXT) lib_a-sf_scalbln.$(OBJEXT) \
- lib_a-sf_trunc.$(OBJEXT)
+ lib_a-sf_logb.$(OBJEXT) lib_a-sf_log2.$(OBJEXT) \
+ lib_a-sf_fdim.$(OBJEXT) lib_a-sf_fma.$(OBJEXT) \
+ lib_a-sf_fmax.$(OBJEXT) lib_a-sf_fmin.$(OBJEXT) \
+ lib_a-sf_fpclassify.$(OBJEXT) lib_a-sf_lrint.$(OBJEXT) \
+ lib_a-sf_lround.$(OBJEXT) lib_a-sf_nearbyint.$(OBJEXT) \
+ lib_a-sf_remquo.$(OBJEXT) lib_a-sf_round.$(OBJEXT) \
+ lib_a-sf_scalbln.$(OBJEXT) lib_a-sf_trunc.$(OBJEXT)
@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \
@USE_LIBTOOL_FALSE@ $(am__objects_2)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
@@ -100,17 +100,17 @@ am__objects_3 = s_finite.lo s_copysign.lo s_modf.lo s_scalbn.lo \
s_cbrt.lo s_exp10.lo s_expm1.lo s_ilogb.lo s_infconst.lo \
s_infinity.lo s_isinf.lo s_isinfd.lo s_isnan.lo s_isnand.lo \
s_log1p.lo s_nan.lo s_nextafter.lo s_pow10.lo s_rint.lo \
- s_logb.lo s_matherr.lo s_lib_ver.lo s_fdim.lo s_fma.lo \
- s_fmax.lo s_fmin.lo s_fpclassify.lo s_lrint.lo s_lround.lo \
- s_nearbyint.lo s_remquo.lo s_round.lo s_scalbln.lo \
+ s_logb.lo s_log2.lo s_matherr.lo s_lib_ver.lo s_fdim.lo \
+ s_fma.lo s_fmax.lo s_fmin.lo s_fpclassify.lo s_lrint.lo \
+ s_lround.lo s_nearbyint.lo s_remquo.lo s_round.lo s_scalbln.lo \
s_signbit.lo s_trunc.lo
am__objects_4 = sf_finite.lo sf_copysign.lo sf_modf.lo sf_scalbn.lo \
sf_cbrt.lo sf_exp10.lo sf_expm1.lo sf_ilogb.lo sf_infinity.lo \
sf_isinf.lo sf_isinff.lo sf_isnan.lo sf_isnanf.lo sf_log1p.lo \
sf_nan.lo sf_nextafter.lo sf_pow10.lo sf_rint.lo sf_logb.lo \
- sf_fdim.lo sf_fma.lo sf_fmax.lo sf_fmin.lo sf_fpclassify.lo \
- sf_lrint.lo sf_lround.lo sf_nearbyint.lo sf_remquo.lo \
- sf_round.lo sf_scalbln.lo sf_trunc.lo
+ sf_log2.lo sf_fdim.lo sf_fma.lo sf_fmax.lo sf_fmin.lo \
+ sf_fpclassify.lo sf_lrint.lo sf_lround.lo sf_nearbyint.lo \
+ sf_remquo.lo sf_round.lo sf_scalbln.lo sf_trunc.lo
@USE_LIBTOOL_TRUE@am_libcommon_la_OBJECTS = $(am__objects_3) \
@USE_LIBTOOL_TRUE@ $(am__objects_4)
libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS)
@@ -278,7 +278,7 @@ src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \
s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c s_infconst.c \
s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
- s_rint.c s_logb.c s_matherr.c s_lib_ver.c \
+ s_rint.c s_logb.c s_log2.c s_matherr.c s_lib_ver.c \
s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c s_lrint.c \
s_lround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
s_signbit.c s_trunc.c
@@ -287,7 +287,7 @@ fsrc = sf_finite.c sf_copysign.c sf_modf.c sf_scalbn.c \
sf_cbrt.c sf_exp10.c sf_expm1.c sf_ilogb.c \
sf_infinity.c sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c \
sf_log1p.c sf_nan.c sf_nextafter.c sf_pow10.c \
- sf_rint.c sf_logb.c \
+ sf_rint.c sf_logb.c sf_log2.c \
sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_fpclassify.c sf_lrint.c \
sf_lround.c sf_nearbyint.c sf_remquo.c sf_round.c \
sf_scalbln.c sf_trunc.c
@@ -495,6 +495,12 @@ lib_a-s_logb.o: s_logb.c
lib_a-s_logb.obj: s_logb.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_logb.obj `if test -f 's_logb.c'; then $(CYGPATH_W) 's_logb.c'; else $(CYGPATH_W) '$(srcdir)/s_logb.c'; fi`
+lib_a-s_log2.o: s_log2.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_log2.o `test -f 's_log2.c' || echo '$(srcdir)/'`s_log2.c
+
+lib_a-s_log2.obj: s_log2.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_log2.obj `if test -f 's_log2.c'; then $(CYGPATH_W) 's_log2.c'; else $(CYGPATH_W) '$(srcdir)/s_log2.c'; fi`
+
lib_a-s_matherr.o: s_matherr.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_matherr.o `test -f 's_matherr.c' || echo '$(srcdir)/'`s_matherr.c
@@ -699,6 +705,12 @@ lib_a-sf_logb.o: sf_logb.c
lib_a-sf_logb.obj: sf_logb.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_logb.obj `if test -f 'sf_logb.c'; then $(CYGPATH_W) 'sf_logb.c'; else $(CYGPATH_W) '$(srcdir)/sf_logb.c'; fi`
+lib_a-sf_log2.o: sf_log2.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_log2.o `test -f 'sf_log2.c' || echo '$(srcdir)/'`sf_log2.c
+
+lib_a-sf_log2.obj: sf_log2.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_log2.obj `if test -f 'sf_log2.c'; then $(CYGPATH_W) 'sf_log2.c'; else $(CYGPATH_W) '$(srcdir)/sf_log2.c'; fi`
+
lib_a-sf_fdim.o: sf_fdim.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fdim.o `test -f 'sf_fdim.c' || echo '$(srcdir)/'`sf_fdim.c
@@ -970,6 +982,10 @@ slog1p.def: s_log1p.c
$(CHEW) < $(srcdir)/s_log1p.c >$@ 2>/dev/null
touch stmp-def
+slog2.def: s_log2.c
+ $(CHEW) < $(srcdir)/s_log2.c >$@ 2>/dev/null
+ touch stmp-def
+
smodf.def: s_modf.c
$(CHEW) < $(srcdir)/s_modf.c >$@ 2>/dev/null
touch stmp-def
diff --git a/newlib/libm/common/s_log2.c b/newlib/libm/common/s_log2.c
new file mode 100644
index 0000000..4683960
--- /dev/null
+++ b/newlib/libm/common/s_log2.c
@@ -0,0 +1,73 @@
+/* @(#)s_log2.c 5.1 93/09/24 */
+/* Modification from s_exp10.c Yaakov Selkowitz 2009. */
+
+/*
+ * ====================================================
+ * 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.
+ * ====================================================
+ */
+
+/*
+FUNCTION
+ <<log2>>, <<log2f>>---base 2 logarithm
+INDEX
+ log2
+INDEX
+ log2f
+
+ANSI_SYNOPSIS
+ #include <math.h>
+ double log2(double <[x]>);
+ float log2f(float <[x]>);
+
+TRAD_SYNOPSIS
+ #include <math.h>
+ double log2(<[x]>);
+ double <[x]>;
+
+ float log2f(<[x]>);
+ float <[x]>;
+
+DESCRIPTION
+ <<log2>> returns the base 2 logarithm of <[x]>.
+
+ <<log2f>> is identical, save that it takes and returns <<float>> values.
+
+RETURNS
+ On success, <<log2>> and <<log2f>> return the calculated value.
+ If the result underflows, the returned value is <<0>>. If the
+ result overflows, the returned value is <<HUGE_VAL>>. In
+ either case, <<errno>> is set to <<ERANGE>>.
+
+PORTABILITY
+ <<log2>> and <<log2f>> are required by ISO/IEC 9899:1999 and the
+ System V Interface Definition (Issue 6).
+*/
+
+/*
+ * wrapper log2(x)
+ */
+
+#include "fdlibm.h"
+#include <errno.h>
+#include <math.h>
+#undef log2
+
+#ifndef _DOUBLE_IS_32BITS
+
+#ifdef __STDC__
+ double log2(double x) /* wrapper log2 */
+#else
+ double log2(x) /* wrapper log2 */
+ double x;
+#endif
+{
+ return (log(x) / M_LOG2_E);
+}
+
+#endif /* defined(_DOUBLE_IS_32BITS) */
diff --git a/newlib/libm/common/sf_log2.c b/newlib/libm/common/sf_log2.c
new file mode 100644
index 0000000..eb8863c
--- /dev/null
+++ b/newlib/libm/common/sf_log2.c
@@ -0,0 +1,48 @@
+/* sf_log2.c -- float version of s_log2.c.
+ * Modification of sf_exp10.c by Yaakov Selkowitz 2009.
+ */
+
+/*
+ * ====================================================
+ * 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.
+ * ====================================================
+ */
+
+/*
+ * wrapper log2f(x)
+ */
+
+#include "fdlibm.h"
+#include <errno.h>
+#include <math.h>
+#undef log2
+#undef log2f
+
+#ifdef __STDC__
+ float log2f(float x) /* wrapper log2f */
+#else
+ float log2f(x) /* wrapper log2f */
+ float x;
+#endif
+{
+ return (logf(x) / (float) M_LOG2_E);
+}
+
+#ifdef _DOUBLE_IS_32BITS
+
+#ifdef __STDC__
+ double log2(double x)
+#else
+ double log2(x)
+ double x;
+#endif
+{
+ return (double) log2f((float) x);
+}
+
+#endif /* defined(_DOUBLE_IS_32BITS) */