From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?R=FCdiger?= Sonderfeld Newsgroups: gmane.emacs.devel Subject: [PATCH] Add support for log2. Date: Thu, 20 Jun 2013 02:03:50 +0200 Message-ID: <1783344.43FasZRPlO@descartes> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1371686646 30420 80.91.229.3 (20 Jun 2013 00:04:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Jun 2013 00:04:06 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 20 02:04:07 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UpSMA-0006lg-Nt for ged-emacs-devel@m.gmane.org; Thu, 20 Jun 2013 02:04:06 +0200 Original-Received: from localhost ([::1]:33775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpSMA-00032C-9s for ged-emacs-devel@m.gmane.org; Wed, 19 Jun 2013 20:04:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpSM5-0002xc-1q for emacs-devel@gnu.org; Wed, 19 Jun 2013 20:04:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpSM2-0003Ul-G5 for emacs-devel@gnu.org; Wed, 19 Jun 2013 20:04:00 -0400 Original-Received: from ptmx.org ([178.63.28.110]:47232) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpSM2-0003Uc-8r for emacs-devel@gnu.org; Wed, 19 Jun 2013 20:03:58 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by ptmx.org (Postfix) with ESMTP id CAE4E217BF; Thu, 20 Jun 2013 02:03:56 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at ptmx.org Original-Received: from ptmx.org ([127.0.0.1]) by localhost (ptmx.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1yyWHViiCIpy; Thu, 20 Jun 2013 02:03:55 +0200 (CEST) Original-Received: from descartes.localnet (chello080108246092.7.14.vie.surfer.at [80.108.246.92]) by ptmx.org (Postfix) with ESMTPSA id 136CD21463; Thu, 20 Jun 2013 02:03:54 +0200 (CEST) User-Agent: KMail/4.10.3 (Linux/3.8.0-23-generic; KDE/4.10.3; x86_64; ; ) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 178.63.28.110 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160713 Archived-At: 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) '> '=E2=89=AF) (if (=3D float-log n) '=3D '=E2=89=A0) (if (< float-log n) '< '=E2=89=AE)))) (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=C3=BCdiger Sonderfeld --- 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) =20 ## Eric Backus 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 . EX= P). =20 if (b =3D=3D 10.0) =09d =3D log10 (d); +#ifdef HAVE_LOG2 + else if (b =3D=3D 2.0) + d =3D log2 (d); +#endif else =09d =3D log (d) / log (b); } return make_float (d); } =20 +DEFUN ("log2", Flog2, Slog2, 1, 1, 0, + doc: /* Return the logarithm base 2 of ARG. */) + (Lisp_Object arg) +{ + double d =3D extract_float (arg); +#ifdef HAVE_LOG2 + d =3D log2 (d); +#else + d =3D 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); =20 --=20 1.8.3.1