This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

log2, log2f


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

SUSv3 requires that log2 and log2f be defined as functions (at least)
and may also be defined as macros.  Right now, though, these are only
defined as macros, and besides being noncompliant, it also creates false
negatives with configure AC_CHECK_FUNC[S] tests.

Here's my first attempt at a patch to define these as functions instead.


Yaakov
Cygwin/X
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEAREIAAYFAknAU08ACgkQpiWmPGlmQSN40QCgmxJVHI69HZnsGv7ls8T7xMRe
KiwAn1RT0GPexXNcCln4xlepSLhGrNoB
=N2BR
-----END PGP SIGNATURE-----
? newlib-log2.patch
Index: libc/include/math.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/math.h,v
retrieving revision 1.33
diff -u -r1.33 math.h
--- libc/include/math.h	23 Apr 2008 23:10:54 -0000	1.33
+++ libc/include/math.h	18 Mar 2009 01:40:23 -0000
@@ -250,7 +250,7 @@
 extern double lgamma _PARAMS((double));
 extern double erf _PARAMS((double));
 extern double erfc _PARAMS((double));
-#define log2(x) (log (x) / _M_LOG2_E)
+extern double log2 _PARAMS((double));
 
 #ifndef __math_68881
 extern double hypot _PARAMS((double, double));
@@ -328,7 +328,7 @@
 extern float lgammaf _PARAMS((float));
 extern float erff _PARAMS((float));
 extern float erfcf _PARAMS((float));
-#define log2f(x) (logf (x) / (float) _M_LOG2_E)
+extern float log2f _PARAMS((float));
 extern float hypotf _PARAMS((float, float));
 #endif /* ! defined (_REENT_ONLY) */
 
Index: libm/common/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libm/common/Makefile.am,v
retrieving revision 1.9
diff -u -r1.9 Makefile.am
--- libm/common/Makefile.am	17 May 2007 18:50:57 -0000	1.9
+++ libm/common/Makefile.am	18 Mar 2009 01:40:26 -0000
@@ -11,7 +11,7 @@
 	s_rint.c s_logb.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
+	s_signbit.c s_trunc.c s_log2.c
 
 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 \
@@ -20,7 +20,7 @@
 	sf_rint.c sf_logb.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
+	sf_scalbln.c sf_trunc.c sf_log2.c
 
 libcommon_la_LDFLAGS = -Xcompiler -nostdlib
 
@@ -94,6 +94,10 @@
 	$(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
Index: libm/common/s_log2.c
===================================================================
RCS file: libm/common/s_log2.c
diff -N libm/common/s_log2.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libm/common/s_log2.c	18 Mar 2009 01:40:26 -0000
@@ -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>> nor <<log2f>> are required by ISO/IEC 9899:1999 and the
+	System V Interface Definition (Issue 6).
+*/
+
+/*
+ * wrapper log2(x)
+ */
+
+#undef log2
+#include "fdlibm.h"
+#include <errno.h>
+#include <math.h>
+
+#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) */
Index: libm/common/sf_log2.c
===================================================================
RCS file: libm/common/sf_log2.c
diff -N libm/common/sf_log2.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libm/common/sf_log2.c	18 Mar 2009 01:40:26 -0000
@@ -0,0 +1,47 @@
+/* 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)
+ */
+
+#undef log2f
+#include "fdlibm.h"
+#include <errno.h>
+#include <math.h>
+
+#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) */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]