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 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: 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 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