* [PATCH] Add support for log2. @ 2013-06-20 0:03 Rüdiger Sonderfeld 2013-06-20 2:15 ` Stefan Monnier 0 siblings, 1 reply; 6+ messages in thread From: Rüdiger Sonderfeld @ 2013-06-20 0:03 UTC (permalink / raw) To: emacs-devel log2(3) is a new function in C99. I think it makes sense adding support for it in Emacs because of the improved accuracy and logarithmus dualis is common in computer science and information theory. The following code snipped (from jlf) shows the improved accuracy for larger numbers: (mapcar (lambda (n) (let ((float-log (log (expt 2 n) 2))) (list (if (> float-log n) '> '≯) (if (= float-log n) '= '≠) (if (< float-log n) '< '≮)))) (number-sequence 0 31)) A feature test is added to configure.ac and a fallback for legacy systems included. * src/floatfns.c (Flog): Add special case for `log2'. (Flog2): New function. * configure.ac: Test for `log2'. Signed-off-by: Rüdiger Sonderfeld <ruediger@c-plusplus.de> --- configure.ac | 2 +- src/floatfns.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a16a52d..6e5c888 100644 --- a/configure.ac +++ b/configure.ac @@ -3235,7 +3235,7 @@ gai_strerror mkstemp getline getdelim sync \ difftime posix_memalign \ getpwent endpwent getgrent endgrent \ touchlock \ -cfmakeraw cfsetspeed copysign __executable_start) +cfmakeraw cfsetspeed copysign __executable_start log2) ## Eric Backus <ericb@lsid.hp.com> says, HP-UX 9.x on HP 700 machines ## has a broken `rint' in some library versions including math library diff --git a/src/floatfns.c b/src/floatfns.c index d7514ec..a7e03e7 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -241,12 +241,29 @@ The function returns the cons cell (SGNFCAND . EXP). if (b == 10.0) d = log10 (d); +#ifdef HAVE_LOG2 + else if (b == 2.0) + d = log2 (d); +#endif else d = log (d) / log (b); } return make_float (d); } +DEFUN ("log2", Flog2, Slog2, 1, 1, 0, + doc: /* Return the logarithm base 2 of ARG. */) + (Lisp_Object arg) +{ + double d = extract_float (arg); +#ifdef HAVE_LOG2 + d = log2 (d); +#else + d = log (d) / log (2.0); +#endif + return make_float(d); +} + DEFUN ("log10", Flog10, Slog10, 1, 1, 0, doc: /* Return the logarithm base 10 of ARG. */) (Lisp_Object arg) @@ -553,6 +570,7 @@ The function returns the cons cell (SGNFCAND . EXP). defsubr (&Sexp); defsubr (&Sexpt); defsubr (&Slog); + defsubr (&Slog2); defsubr (&Slog10); defsubr (&Ssqrt); -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Add support for log2. 2013-06-20 0:03 [PATCH] Add support for log2 Rüdiger Sonderfeld @ 2013-06-20 2:15 ` Stefan Monnier 2013-06-20 2:36 ` Paul Eggert 0 siblings, 1 reply; 6+ messages in thread From: Stefan Monnier @ 2013-06-20 2:15 UTC (permalink / raw) To: Rüdiger Sonderfeld; +Cc: emacs-devel > A feature test is added to configure.ac and a fallback for legacy > systems included. > * src/floatfns.c (Flog): Add special case for `log2'. > (Flog2): New function. > * configure.ac: Test for `log2'. Looks OK, feel free to install (with an entry to etc/NEWS as well). Stefan ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add support for log2. 2013-06-20 2:15 ` Stefan Monnier @ 2013-06-20 2:36 ` Paul Eggert 2013-06-20 12:56 ` Rüdiger Sonderfeld 0 siblings, 1 reply; 6+ messages in thread From: Paul Eggert @ 2013-06-20 2:36 UTC (permalink / raw) To: Stefan Monnier; +Cc: Rüdiger Sonderfeld, emacs-devel Elisp already has a syntax for log2 (X), namely (log X 2), so how about the following more-conservative change? This avoids adding the "log2" function to the Emacs namespace, thus no need for a NEWS entry, doc change, etc. (I know the same argument applies to log10, but that horse left the barn long ago.) === modified file 'ChangeLog' --- ChangeLog 2013-06-19 20:10:57 +0000 +++ ChangeLog 2013-06-20 02:32:16 +0000 @@ -1,3 +1,7 @@ +2013-06-20 Rüdiger Sonderfeld <ruediger@c-plusplus.de> + + * configure.ac (log2): Check for this function. + 2013-06-19 Juanma Barranquero <lekktu@gmail.com> * .bzrignore: Add GNU GLOBAL files. === modified file 'configure.ac' --- configure.ac 2013-06-17 06:03:19 +0000 +++ configure.ac 2013-06-20 02:31:58 +0000 @@ -3235,7 +3235,7 @@ difftime posix_memalign \ getpwent endpwent getgrent endgrent \ touchlock \ -cfmakeraw cfsetspeed copysign __executable_start) +cfmakeraw cfsetspeed copysign __executable_start log2) ## Eric Backus <ericb@lsid.hp.com> says, HP-UX 9.x on HP 700 machines ## has a broken `rint' in some library versions including math library === modified file 'src/ChangeLog' --- src/ChangeLog 2013-06-19 20:10:57 +0000 +++ src/ChangeLog 2013-06-20 02:31:58 +0000 @@ -1,3 +1,8 @@ +2013-06-20 Rüdiger Sonderfeld <ruediger@c-plusplus.de> + + * floatfns.c (Flog) [HAVE_LOG2]: Use log2 if available and if the + base is 2; in practice it's more accurate. + 2013-06-19 Juanma Barranquero <lekktu@gmail.com> * sound.c (string_default): Move to !WINDOWSNT section. === modified file 'src/floatfns.c' --- src/floatfns.c 2013-06-20 01:19:43 +0000 +++ src/floatfns.c 2013-06-20 02:31:58 +0000 @@ -33,10 +33,10 @@ acosh, atanh, cbrt, *copysign, erf, erfc, exp2, expm1, fdim, fma, fmax, fmin, fpclassify, hypot, ilogb, isfinite, isgreater, isgreaterequal, isinf, isless, islessequal, islessgreater, *isnan, - isnormal, isunordered, lgamma, log1p, log2, *logb (approximately), - lrint/llrint, lround/llround, nan, nearbyint, nextafter, - nexttoward, remainder, remquo, *rint, round, scalbln, scalbn, - signbit, tgamma, trunc. + isnormal, isunordered, lgamma, log1p, *log2 [via (log X 2)], *logb + (approximately), lrint/llrint, lround/llround, nan, nearbyint, + nextafter, nexttoward, remainder, remquo, *rint, round, scalbln, + scalbn, signbit, tgamma, trunc. */ #include <config.h> @@ -252,6 +252,10 @@ if (b == 10.0) d = log10 (d); +#if HAVE_LOG2 + else if (b == 2.0) + d = log2 (d); +#endif else d = log (d) / log (b); } ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add support for log2. 2013-06-20 2:36 ` Paul Eggert @ 2013-06-20 12:56 ` Rüdiger Sonderfeld 2013-06-20 14:27 ` Paul Eggert 0 siblings, 1 reply; 6+ messages in thread From: Rüdiger Sonderfeld @ 2013-06-20 12:56 UTC (permalink / raw) To: emacs-devel; +Cc: Paul Eggert, Stefan Monnier On Wednesday 19 June 2013 19:36:14 Paul Eggert wrote: > Elisp already has a syntax for log2 (X), namely (log X 2), > so how about the following more-conservative change? > This avoids adding the "log2" function to the Emacs namespace, > thus no need for a NEWS entry, doc change, etc. > > (I know the same argument applies to log10, but > that horse left the barn long ago.) I would be fine with that. Common Lisp has no log2 or log10 either, so it probably makes sense. However I think in that case we should consider deprecating log10 for the sake of consistency. The existence of a log10 seems to imply a lack of a log2. Regards, Rüdiger ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add support for log2. 2013-06-20 12:56 ` Rüdiger Sonderfeld @ 2013-06-20 14:27 ` Paul Eggert 2013-06-20 14:36 ` Rüdiger Sonderfeld 0 siblings, 1 reply; 6+ messages in thread From: Paul Eggert @ 2013-06-20 14:27 UTC (permalink / raw) To: Rüdiger Sonderfeld; +Cc: Stefan Monnier, emacs-devel On 06/20/2013 05:56 AM, Rüdiger Sonderfeld wrote: > we should consider > deprecating log10 for the sake of consistency. Sounds good. I committed all that, as trunk bzr 113098. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add support for log2. 2013-06-20 14:27 ` Paul Eggert @ 2013-06-20 14:36 ` Rüdiger Sonderfeld 0 siblings, 0 replies; 6+ messages in thread From: Rüdiger Sonderfeld @ 2013-06-20 14:36 UTC (permalink / raw) To: emacs-devel; +Cc: Paul Eggert, Stefan Monnier On Thursday 20 June 2013 07:27:45 Paul Eggert wrote: > On 06/20/2013 05:56 AM, Rüdiger Sonderfeld wrote: > > we should consider > > deprecating log10 for the sake of consistency. > > Sounds good. I committed all that, as trunk bzr 113098. Thanks! ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-06-20 14:36 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-06-20 0:03 [PATCH] Add support for log2 Rüdiger Sonderfeld 2013-06-20 2:15 ` Stefan Monnier 2013-06-20 2:36 ` Paul Eggert 2013-06-20 12:56 ` Rüdiger Sonderfeld 2013-06-20 14:27 ` Paul Eggert 2013-06-20 14:36 ` Rüdiger Sonderfeld
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.