Last active
March 15, 2018 01:27
-
-
Save chuntaro/0010f95fe075adef80cf98fb2f217589 to your computer and use it in GitHub Desktop.
素の Emacs で Calc の多倍長整数を使って円周率を1000桁計算する方法
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桁は未収束の為除いたものが正しい値 | |
| (defmath mpiarccot (x) | |
| (let ((base (expt 10 (+ 1000 4))) | |
| (a x) | |
| (b 1) | |
| pos | |
| (sum 0)) | |
| (while (> (setq pos (idiv base (* a b))) 1) | |
| (setq sum (+ sum (if (/= (logand 2 b) 0) (- pos) pos)) | |
| a (* a x x) | |
| b (+ b 2))) | |
| sum)) | |
| (calc-eval "4 * (4 * mpiarccot(5) - mpiarccot(239))") ; => "3141592653...42019893644" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment