Raymond Toy pushed to branch master at cmucl / cmucl Commits: 6d264493 by Raymond Toy at 2026-01-20T07:02:39-08:00 Fix #428: Add some constants for common values in irrat.lisp - - - - - ea927341 by Raymond Toy at 2026-01-20T07:02:40-08:00 Merge branch 'issue-428-add-constants-for-irrat' into 'master' Fix #428: Add some constants for common values in irrat.lisp Closes #428 See merge request cmucl/cmucl!344 - - - - - 3 changed files: - src/code/irrat.lisp - src/general-info/release-22a.md - src/i18n/locale/cmucl.pot Changes: ===================================== src/code/irrat.lisp ===================================== @@ -24,6 +24,18 @@ (defconstant pi 3.14159265358979323846264338327950288419716939937511L0) ;(defconstant e 2.71828182845904523536028747135266249775724709369996L0) +(defconstant +log-2d0+ + (log 2d0) + "Natural log of 2d0") + +(defconstant +log-2w0+ + (log 2w0) + "Natural log of 2w0") + +(defconstant +log2-e+ + (log (exp 1d0) 2d0) + "Base 2 logarithm of e") + ;;; Make these INLINE, since the call to C is at least as compact as a Lisp ;;; call, and saves number consing to boot. ;;; @@ -488,14 +500,14 @@ complex) (if (and (zerop base) (plusp (realpart power))) (* base power) - (exp (* power (* (log2 base 1w0) (log 2w0)))))) + (exp (* power (* (log2 base 1w0) +log-2w0+))))) (((foreach fixnum (or bignum ratio) single-float double-float) (foreach (complex double-float))) ;; Result should have double-float accuracy. Use log2 in ;; case the base won't fit in a double-float. (if (and (zerop base) (plusp (realpart power))) (* base power) - (exp (* power (* (log2 base) (log 2d0)))))) + (exp (* power (* (log2 base) +log-2d0+))))) ((double-float (foreach (complex rational) (complex single-float))) (if (and (zerop base) (plusp (realpart power))) @@ -508,7 +520,7 @@ ;; in case the base won't fit in a double-float. (if (and (zerop base) (plusp (realpart power))) (* base power) - (exp (* power (* (log2 base 1w0) (log 2w0)))))) + (exp (* power (* (log2 base 1w0) +log-2w0+))))) (((foreach fixnum (or bignum ratio) single-float) (foreach (complex rational) (complex single-float))) (if (and (zerop base) (plusp (realpart power))) @@ -566,18 +578,18 @@ ;; log(2), with the precision specified by the type of F (number-dispatch ((f real)) ((double-float) - #.(log 2d0)) + +log-2d0+) #+double-double ((double-double-float) - #.(log 2w0)))) + +log-2w0+))) (log-2-pi (f) ;; log(pi), with the precision specified by the type of F (number-dispatch ((f real)) ((double-float) - #.(/ pi (log 2d0))) + #.(/ pi +log-2d0+)) #+double-double ((double-double-float) - #.(/ dd-pi (log 2w0))))) + #.(/ dd-pi +log-2w0+)))) (log1p (x) ;; log(1+x), with the precision specified by the type of ;; X @@ -827,7 +839,7 @@ (if (minusp number) (complex (coerce (log (- number)) 'single-float) (coerce pi 'single-float)) - (coerce (/ (log2 number) #.(log (exp 1d0) 2d0)) 'single-float))) + (coerce (/ (log2 number) +log2-e+) 'single-float))) ((ratio) (if (minusp number) (complex (coerce (log (- number)) 'single-float) @@ -852,7 +864,7 @@ (coerce (%log1p (coerce (- number 1) 'double-float)) 'single-float) (coerce (/ (- (log2 top) (log2 bot)) - #.(log (exp 1d0) 2d0)) + +log2-e+) 'single-float))))) (((foreach single-float double-float)) ;; Is (log -0) -infinity (libm.a) or -infinity + i*pi (Kahan)? @@ -1393,7 +1405,7 @@ This is for use with J /= 0 only when |z| is huge." (let ((t0 #.(/ 1 (sqrt 2.0d0))) (t1 1.2d0) (t2 3d0) - (ln2 #.(log 2d0)) + (ln2 +log-2d0+) (x (float (realpart z) 1.0d0)) (y (float (imagpart z) 1.0d0))) (multiple-value-bind (rho k) ===================================== src/general-info/release-22a.md ===================================== @@ -28,6 +28,7 @@ public domain. * #373: Add macros to handle temp files and directories * #387: Update CLX from upstream to version from 2024-09-11 * #408: Add C functions to get user name and home dir + * #428: Add some constants for common values in irrat.lisp * #437: Use `realpath` to find the lisp executable * #444: `unix-stat` and friends return wrong timestamp * #449: Touch 64-bit timestamp.txt with desired time for testing ===================================== src/i18n/locale/cmucl.pot ===================================== @@ -5008,6 +5008,18 @@ msgid "" " (= x (float (rationalize x) x))" msgstr "" +#: src/code/irrat.lisp +msgid "Natural log of 2d0" +msgstr "" + +#: src/code/irrat.lisp +msgid "Natural log of 2w0" +msgstr "" + +#: src/code/irrat.lisp +msgid "Base 2 logarithm of e" +msgstr "" + #: src/code/irrat.lisp msgid "Return e raised to the power NUMBER." msgstr "" View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/3f733bae60b20dadee5f4f0... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/3f733bae60b20dadee5f4f0... You're receiving this email because of your account on gitlab.common-lisp.net.