Skip to content

Instantly share code, notes, and snippets.

@chuntaro
Created March 15, 2018 02:23
Show Gist options
  • Select an option

  • Save chuntaro/64b5a6dec747bd096be86c983ede4f8a to your computer and use it in GitHub Desktop.

Select an option

Save chuntaro/64b5a6dec747bd096be86c983ede4f8a to your computer and use it in GitHub Desktop.
円周率をマチンの公式を使って10000桁計算
;; 出力結果は3の後ろに小数点が無いのと最後の4桁は未収束の為除いたものが正しい値
(defpackage #:pi
(:use #:cl))
(in-package #:pi)
(declaim (optimize (speed 3) (debug 0) (safety 0)))
(defun mpiarccot (x)
(loop with base = (expt 10 (+ 10000 4))
for a = x then (* a x x)
for b from 1 by 2
for pos = (truncate base (* a b))
while (> pos 1)
sum (if (logbitp 1 b) (- pos) pos)))
(defun calc ()
(* 4 (- (* 4 (mpiarccot 5))
(mpiarccot 239))))
(defparameter mypi 0)
(time (setq mypi (calc)))
(print mypi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment