Groups | Search | Server Info | Login | Register
Groups > gnu.emacs.help > #60981
| Path | csiph.com!weretis.net!feeder9.news.weretis.net!newsfeed.hasname.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!nnrp.usenet.blueworldhosting.com!.POSTED!not-for-mail |
|---|---|
| From | Richard Smith <null@void.com> |
| Newsgroups | gnu.emacs.help |
| Subject | thanks - calculate pi fn. in elisp |
| Date | Tue, 09 Jul 2024 19:48:48 +0100 |
| Organization | BWH Usenet Archive (https://usenet.blueworldhosting.com) |
| Message-ID | <m11q42e6zz.fsf@void.com> (permalink) |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | nnrp.usenet.blueworldhosting.com; logging-data="15767"; mail-complaints-to="usenet@blueworldhosting.com" |
| User-Agent | Gnus/5.13 (Gnus v5.13) |
| Cancel-Lock | sha1:9r8R42hBaBfPgBY5oHoCtE1knqI= sha1:g7t71y6PWRU+qlaIS5O+pzZcG5Q= sha256:io8tKDD40lh0gH9W1X9fzJNkAQ0fnkEj2x/fus8ai1k= sha1:LI7CdBN4vaFCZV8h47Ttqtw538A= sha256:19Xxh4P8fRSzRdFT6h/tBuYGAGZvKeFYijpvG6GMa1k= |
| Xref | csiph.com gnu.emacs.help:60981 |
Show key headers only | View raw
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