Groups | Search | Server Info | Login | Register
Groups > gnu.emacs.help > #60981
| From | Richard Smith <null@void.com> |
|---|---|
| Newsgroups | gnu.emacs.help |
| Subject | thanks - calculate pi fn. in elisp |
| Date | 2024-07-09 19:48 +0100 |
| Organization | BWH Usenet Archive (https://usenet.blueworldhosting.com) |
| Message-ID | <m11q42e6zz.fsf@void.com> (permalink) |
I know this is "help" and for emacs as a program,
but for what it's worth,
sort of as a thanks,
this is what I as a welder and bit of an engineer managed to do
readily on finding there is a formula for calculating the value of
pi...
You will know better ways, but this "scribble" was a nice bit of
learning maths.
Thanks everyone for help along the way
Rich S
--------------------------------
(setq max-lisp-eval-depth (expt 2 20))
(defun h-invnsq (this-n invnsq-sum)
(if (zerop this-n)
invnsq-sum
(h-invnsq (1- this-n) (+ invnsq-sum (/ 1e0 (expt this-n 2))))))
(defun pi-calc (n-to)
"calculates Pi - arg integer is to how 1/n^2 integer to sum"
(sqrt (* 6 (h-invnsq n-to 0))))
(= (sqrt 6) (pi-calc 1)) ;; t
(pi-calc 10) ;; 3.04936163598207
(pi-calc 100) ;; 3.132076531809106
(pi-calc 1000) ;; 3.140638056205993
(pi-calc 10000) ;; 3.1414971639472093
pi ;; 3.141592653589793
Back to gnu.emacs.help | Previous | Next — Next in thread | Find similar
thanks - calculate pi fn. in elisp Richard Smith <null@void.com> - 2024-07-09 19:48 +0100
TCO with named-let via macros (was: thanks - calculate pi fn. in elisp) Axel Reichert <mail@axel-reichert.de> - 2024-07-09 23:15 +0200
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-07-10 06:28 +0100
Re: TCO with named-let via macros steve g <sgonedes1977@gmail.com> - 2024-08-10 15:56 -0400
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-08-10 22:28 +0100
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-07-10 06:36 +0100
Re: TCO with named-let via macros steve g <sgonedes1977@gmail.com> - 2024-08-10 16:22 -0400
Re: TCO with named-let via macros Axel Reichert <mail@axel-reichert.de> - 2024-08-10 23:15 +0200
Re: TCO with named-let via macros steve g <sgonedes1977@gmail.com> - 2024-08-11 14:56 -0400
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2025-04-08 10:26 +0100
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-07-10 06:59 +0100
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-07-10 09:18 +0100
Re: TCO with named-let via macros steve g <sgonedes1977@gmail.com> - 2024-08-10 16:26 -0400
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-08-10 22:51 +0100
csiph-web