Skip to content

Commit

Permalink
Add more Machin-like formulae for computing π
Browse files Browse the repository at this point in the history
  • Loading branch information
Samayel committed Nov 24, 2015
1 parent 6354a73 commit 1122e6a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
20 changes: 12 additions & 8 deletions src/Math/Series/pi_machin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ module Machin

using Brainstorm.Math.Series.Arctan: arctansum

euler(digits::Integer) = arctansum(digits, [2, 3], 4*[1, 1])
hermann(digits::Integer) = arctansum(digits, [2, 7], 4*[2, -1])
hutton(digits::Integer) = arctansum(digits, [3, 7], 4*[2, 1])
machin(digits::Integer) = arctansum(digits, [5, 239], 4*[4, -1])
euler(digits::Integer) = arctansum(digits, [2, 3], 4*[1, 1])
hermann(digits::Integer) = arctansum(digits, [2, 7], 4*[2, -1])
hutton(digits::Integer) = arctansum(digits, [3, 7], 4*[2, 1])
machin(digits::Integer) = arctansum(digits, [5, 239], 4*[4, -1])

gauss(digits::Integer) = arctansum(digits, [18, 57, 239], 4*[12, 8, -5])
strassnitzky(digits::Integer) = arctansum(digits, [ 2, 5, 8], 4*[ 1, 1, 1])
gauss(digits::Integer) = arctansum(digits, [18, 57, 239], 4*[12, 8, -5])
strassnitzky(digits::Integer) = arctansum(digits, [ 2, 5, 8], 4*[ 1, 1, 1])
klingenstierna(digits::Integer) = arctansum(digits, [10, 239, 515], 4*[ 8, -1, -4])
euler3(digits::Integer) = arctansum(digits, [ 5, 70, 99], 4*[ 4, -1, 1])
loney(digits::Integer) = arctansum(digits, [ 4, 20, 1985], 4*[ 3, 1, 1])
stoermer(digits::Integer) = arctansum(digits, [ 8, 57, 239], 4*[ 6, 2, 1])

takano1982(digits::Integer) = arctansum(digits, [49, 57, 239, 110443], 4*[12, 32, -5, 12])
stoermer1896(digits::Integer) = arctansum(digits, [57, 239, 682, 12943], 4*[44, 7, -12, 24])
takano1982(digits::Integer) = arctansum(digits, [49, 57, 239, 110443], 4*[12, 32, -5, 12])
stoermer1896(digits::Integer) = arctansum(digits, [57, 239, 682, 12943], 4*[44, 7, -12, 24])

hwang1997(digits::Integer) = arctansum(digits, [239, 1023, 5832, 110443, 4841182, 6826318], 4*[183, 32, -68, 12, -12, -100])
hwang2003(digits::Integer) = arctansum(digits, BigInt[239, 1023, 5832, 113021, 6826318, 33366019650, 43599522992503626068], 4*[183, 32, -68, 12, -100, -12, 12])
Expand Down
24 changes: 16 additions & 8 deletions test/Math/Series/pi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ function test_pi_chudnovsky()
end

function test_pi_machin()
euler = Brainstorm.Math.Series.Pi.Machin.euler
hermann = Brainstorm.Math.Series.Pi.Machin.hermann
hutton = Brainstorm.Math.Series.Pi.Machin.hutton
machin = Brainstorm.Math.Series.Pi.Machin.machin
euler = Brainstorm.Math.Series.Pi.Machin.euler
hermann = Brainstorm.Math.Series.Pi.Machin.hermann
hutton = Brainstorm.Math.Series.Pi.Machin.hutton
machin = Brainstorm.Math.Series.Pi.Machin.machin

gauss = Brainstorm.Math.Series.Pi.Machin.gauss
strassnitzky = Brainstorm.Math.Series.Pi.Machin.strassnitzky
gauss = Brainstorm.Math.Series.Pi.Machin.gauss
strassnitzky = Brainstorm.Math.Series.Pi.Machin.strassnitzky
klingenstierna = Brainstorm.Math.Series.Pi.Machin.klingenstierna
euler3 = Brainstorm.Math.Series.Pi.Machin.euler3
loney = Brainstorm.Math.Series.Pi.Machin.loney
stoermer = Brainstorm.Math.Series.Pi.Machin.stoermer

takano1982 = Brainstorm.Math.Series.Pi.Machin.takano1982
stoermer1896 = Brainstorm.Math.Series.Pi.Machin.stoermer1896
takano1982 = Brainstorm.Math.Series.Pi.Machin.takano1982
stoermer1896 = Brainstorm.Math.Series.Pi.Machin.stoermer1896

hwang1997 = Brainstorm.Math.Series.Pi.Machin.hwang1997
hwang2003 = Brainstorm.Math.Series.Pi.Machin.hwang2003
Expand All @@ -36,6 +40,10 @@ function test_pi_machin()

@test all([gauss(d) for d in (1, 10, 100, 1_000, 10_000)] - expected .== 0)
@test all([strassnitzky(d) for d in (1, 10, 100, 1_000, 10_000)] - expected .== 0)
@test all([klingenstierna(d) for d in (1, 10, 100, 1_000, 10_000)] - expected .== 0)
@test all([euler3(d) for d in (1, 10, 100, 1_000, 10_000)] - expected .== 0)
@test all([loney(d) for d in (1, 10, 100, 1_000, 10_000)] - expected .== 0)
@test all([stoermer(d) for d in (1, 10, 100, 1_000, 10_000)] - expected .== 0)

@test all([takano1982(d) for d in (1, 10, 100, 1_000, 10_000)] - expected .== 0)
@test all([stoermer1896(d) for d in (1, 10, 100, 1_000, 10_000)] - expected .== 0)
Expand Down

0 comments on commit 1122e6a

Please sign in to comment.