Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: ports/gambc_ppapi/scm/pi.scm

Issue 150413008: Initial support for gambit-scheme v4.7.0 Base URL: https://chromium.googlesource.com/external/naclports.git@master
Patch Set: Add support for pnacl Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ports/gambc_ppapi/repl_.c ('k') | ports/glibc-compat/src/getprotobyname_r.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 (define (pi num)
2 (define (pi-brent-salamin-approximate base k) ; k is number of digits
3 (define base^k (expt base k))
4 (define (fixed.+ x y)
5 (+ x y))
6
7 (define (fixed.- x y)
8 (- x y))
9
10 (define (fixed.* x y)
11 (quotient (* x y) base^k))
12
13 (define (fixed.square x)
14 (fixed.* x x))
15
16 (define (fixed./ x y)
17 (quotient (* x base^k) y))
18
19 (define (fixed.sqrt x)
20 (integer-sqrt (* x base^k)))
21
22 (define (number->fixed x)
23 (round (* x base^k)))
24
25 (define (fixed->number x)
26 (/ x base^k))
27
28 (let ((one (number->fixed 1)))
29 (let loop ((a one)
30 (b (fixed.sqrt (quotient one 2)))
31 (t (quotient one 4))
32 (x 1))
33 (if (= a b)
34 (quotient (* a a) t)
35 (let ((new-a (quotient (fixed.+ a b) 2)))
36 (loop new-a
37 (integer-sqrt (* a b))
38 (fixed.- t (* x (fixed.square (fixed.- new-a a))))
39 (* 2 x)))))))
40
41 (define (pi-brent-salamin base k) ; k is number of digits
42 (let ((n (ceiling (inexact->exact (+ 2 (log k))))))
43 (quotient (pi-brent-salamin-approximate base (+ k n)) (expt base n))))
44
45 (pi-brent-salamin-approximate 10 num))
OLDNEW
« no previous file with comments | « ports/gambc_ppapi/repl_.c ('k') | ports/glibc-compat/src/getprotobyname_r.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698