From 89561f72e587677618afa2fd6962704e841e39e8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 20 Jun 2013 07:15:42 -0700 Subject: [PATCH] Add log2 support and make log10 obsolete for consistency. * configure.ac (log2): Check for this function. * doc/lispref/numbers.texi (Math Functions): Remove obsolete function log10. * lisp/subr.el (log10): Move here from C code, and declare as obsolete. All uses of (log10 X) replaced with (log X 10). * src/floatfns.c (Flog) [HAVE_LOG2]: Use log2 if available and if the base is 2; this is more accurate. (Flog10): Move to Lisp (marked obsolete there). --- ChangeLog | 4 ++++ configure.ac | 2 +- doc/lispref/ChangeLog | 4 ++++ doc/lispref/numbers.texi | 5 ----- etc/NEWS | 1 + lisp/ChangeLog | 5 +++++ lisp/allout.el | 4 ++-- lisp/calc/calc.el | 2 +- lisp/subr.el | 5 +++++ lisp/textmodes/rst.el | 4 ++-- src/ChangeLog | 9 +++++++++ src/floatfns.c | 25 ++++++++++--------------- 12 files changed, 44 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index f73ab05e910..097a099b56f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-06-20 Rüdiger Sonderfeld + + * configure.ac (log2): Check for this function. + 2013-06-19 Juanma Barranquero * .bzrignore: Add GNU GLOBAL files. diff --git a/configure.ac b/configure.ac index a16a52d43ad..6e5c888b437 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 says, HP-UX 9.x on HP 700 machines ## has a broken `rint' in some library versions including math library diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 65fc76d15f5..c00d3392908 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,7 @@ +2013-06-20 Paul Eggert + + * numbers.texi (Math Functions): Remove obsolete function log10. + 2013-06-19 Stefan Monnier * modes.texi (Mode Line Data, Properties in Mode): Advertise `keymap' diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi index eeebac6bf72..2b6f31b670b 100644 --- a/doc/lispref/numbers.texi +++ b/doc/lispref/numbers.texi @@ -1156,11 +1156,6 @@ This function returns the logarithm of @var{arg}, with base returns a NaN. @end defun -@defun log10 arg -This function returns the logarithm of @var{arg}, with base 10: -@code{(log10 @var{x})} @equiv{} @code{(log @var{x} 10)}. -@end defun - @defun expt x y This function returns @var{x} raised to power @var{y}. If both arguments are integers and @var{y} is positive, the result is an diff --git a/etc/NEWS b/etc/NEWS index a2f96f4bf92..475b4b26fdb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -469,6 +469,7 @@ file using `set-file-extended-attributes'. ** New macro with-eval-after-load. Like eval-after-load, but better behaved. ** Obsoleted functions: +*** `log10' *** `dont-compile' *** `lisp-complete-symbol' *** `field-complete' diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0a9187435f1..1bfad0f9179 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2013-06-20 Paul Eggert + + * subr.el (log10): Move here from C code, and declare as obsolete. + All uses of (log10 X) replaced with (log X 10). + 2013-06-20 Juanma Barranquero * emacs-lisp/tabulated-list.el (tabulated-list-format): Fix typo. diff --git a/lisp/allout.el b/lisp/allout.el index 1e4134b3ccf..a0d61eb6f35 100644 --- a/lisp/allout.el +++ b/lisp/allout.el @@ -5342,7 +5342,7 @@ Optional arg CONTEXT indicates interior levels to include." (cons (make-string (1+ (truncate (if (zerop (car flat-index)) 1 - (log10 (car flat-index))))) + (log (car flat-index) 10)))) ? ) result))) (setq flat-index (cdr flat-index))) @@ -5382,7 +5382,7 @@ Optional arg CONTEXT indicates interior levels to include." (cons (make-string (1+ (truncate (if (zerop (car flat-index)) 1 - (log10 (car flat-index))))) + (log (car flat-index) 10)))) ? ) result))) (setq flat-index (cdr flat-index))) diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el index bd5c9089bcc..8a17ad7ce30 100644 --- a/lisp/calc/calc.el +++ b/lisp/calc/calc.el @@ -2485,7 +2485,7 @@ the United States." (defconst math-bignum-digit-length - (truncate (/ (log10 (/ most-positive-fixnum 2)) 2)) + (truncate (/ (log (/ most-positive-fixnum 2) 10) 2)) "The length of a \"digit\" in Calc bignums. If a big integer is of the form (bigpos N0 N1 ...), this is the length of the allowable Emacs integers N0, N1,... diff --git a/lisp/subr.el b/lisp/subr.el index eba99b839e6..b8a62023805 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1206,6 +1206,11 @@ is converted into a string by expressing it in decimal." (declare (obsolete make-hash-table "22.1")) (make-hash-table :test (or test 'eql))) +(defun log10 (x) + "Return (log X 10), the log base 10 of X." + (declare (obsolete log "24.4")) + (log x 10)) + ;; These are used by VM and some old programs (defalias 'focus-frame 'ignore "") (make-obsolete 'focus-frame "it does nothing." "22.1") diff --git a/lisp/textmodes/rst.el b/lisp/textmodes/rst.el index 01981175e1d..a841ec39314 100644 --- a/lisp/textmodes/rst.el +++ b/lisp/textmodes/rst.el @@ -2419,8 +2419,8 @@ level to align." ;; for the numbers. (if (cdr node) (setq fmt (format "%%-%dd" - (1+ (floor (log10 (length - (cdr node)))))))))) + (1+ (floor (log (length (cdr node)) + 10)))))))) (dolist (child (cdr node)) (rst-toc-insert-node child diff --git a/src/ChangeLog b/src/ChangeLog index 68138e46b6b..c503da29732 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2013-06-20 Paul Eggert + + * floatfns.c (Flog10): Move to Lisp (marked obsolete there). + +2013-06-20 Rüdiger Sonderfeld + + * floatfns.c (Flog) [HAVE_LOG2]: Use log2 if available and if the + base is 2; this is more accurate. + 2013-06-19 Juanma Barranquero * sound.c (string_default): Move to !WINDOWSNT section. diff --git a/src/floatfns.c b/src/floatfns.c index dd6d3dfe582..f3d0936f888 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -25,7 +25,8 @@ along with GNU Emacs. If not, see . */ /* C89 requires only the following math.h functions, and Emacs omits the starred functions since we haven't found a use for them: acos, asin, atan, atan2, ceil, cos, *cosh, exp, fabs, floor, fmod, - frexp, ldexp, log, log10, *modf, pow, sin, *sinh, sqrt, tan, *tanh. + frexp, ldexp, log, log10 [via (log X 10)], *modf, pow, sin, *sinh, + sqrt, tan, *tanh. C99 and C11 require the following math.h functions in addition to the C89 functions. Of these, Emacs currently exports only the @@ -33,10 +34,10 @@ along with GNU Emacs. If not, see . */ 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 @@ -252,21 +253,16 @@ If the optional argument BASE is given, return log ARG using that base. */) 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); } return make_float (d); } -DEFUN ("log10", Flog10, Slog10, 1, 1, 0, - doc: /* Return the logarithm base 10 of ARG. */) - (Lisp_Object arg) -{ - double d = extract_float (arg); - d = log10 (d); - return make_float (d); -} - DEFUN ("sqrt", Fsqrt, Ssqrt, 1, 1, 0, doc: /* Return the square root of ARG. */) (Lisp_Object arg) @@ -564,7 +560,6 @@ syms_of_floatfns (void) defsubr (&Sexp); defsubr (&Sexpt); defsubr (&Slog); - defsubr (&Slog10); defsubr (&Ssqrt); defsubr (&Sabs); -- 2.39.2