Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-sbcl (error "This only works using SBCL")
- (declaim (optimize (speed 3)
- (debug 0)
- (safety 0)))
- (defmacro gen-arccot (sign opposite)
- `(,(intern (format nil "~a~a" 'arccot sign)) (x-rest n x-elevate product)
- "Arccotangent calculator, uses"
- (declare (type integer x-rest n))
- (declare (type bignum x-elevate product))
- (let ((term (floor x-elevate n)))
- (if (zerop term)
- product
- (,(intern (format nil "~a~a" 'arccot opposite)) x-rest (+ n 2)
- (the bignum (floor x-elevate x-rest))
- (the bignum (,(intern (format nil "~a" sign)) product term )))))))
- (defun pidigits (x-digits)
- "Calculate x-digits of pi using Machin's formula"
- (labels ((gen-arccot + -)
- (gen-arccot - +))
- (let* ((limit (expt 10 (+ 10 x-digits)))
- (first-thread (sb-thread:make-thread
- (lambda () (* 44 (the bignum (arccot+ 3249 1 (the bignum (floor limit 57)) 1))))))
- (second-thread (sb-thread:make-thread
- (lambda () (* 7 (the bignum (arccot+ 57121 1 (the bignum (floor limit 239)) 1))))))
- (third-thread (sb-thread:make-thread
- (lambda () (* -12 (the bignum (arccot+ 465124 1 (the bignum (floor limit 682)) 1))))))
- (fourth-thread (sb-thread:make-thread
- (lambda () (* 24 (the bignum (arccot+ 167521249 1 (the bignum (floor limit 12943)) 1)))))))
- (declare (type bignum limit))
- (sb-thread:thread-yield)
- (format nil "3.~a" (the bignum (rem
- (the bignum (floor
- (the bignum (* 4
- (the bignum (+
- (the bignum (sb-thread:join-thread fourth-thread))
- (the bignum (sb-thread:join-thread third-thread))
- (the bignum (sb-thread:join-thread second-thread))
- (the bignum (sb-thread:join-thread first-thread))))))
- 10000000000))
- (/ limit 10000000000)))))))
- (if (not (cadr *posix-argv*))
- (format t "Error: you should pass an argument~%")
- (let ((n (parse-integer (cadr *posix-argv*))))
- (if (not (typep n 'integer))
- (print "The argument should be a integer~%")
- (print (pidigits n)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement