Last active
November 20, 2019 05:49
-
-
Save chuntaro/31234b501f1416c827ae098ebe080aa4 to your computer and use it in GitHub Desktop.
Emacs 27 で円周率の計算
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; 出力結果は 3 の後ろに小数点を付けて最後の 4 桁は未収束の為除いたものが正しい値 | |
| ;; 2019/11/20: 27 で追加された benchmark-progn を使うように変更 | |
| (defun bignum-arccot (x) | |
| (let ((base (expt 10 (+ 10000 4))) | |
| (a x) | |
| (b 1) | |
| pos | |
| (sum 0)) | |
| (while (< 1 (setq pos (truncate base (* a b)))) | |
| (setq sum (+ sum (if (/= 0 (logand 2 b)) (- pos) pos)) | |
| a (* a x x) | |
| b (+ b 2))) | |
| sum)) | |
| (defun calc () | |
| (* 4 (- (* 4 (bignum-arccot 5)) | |
| (bignum-arccot 239)))) | |
| (benchmark-progn | |
| (message "pi = %d" (calc))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment