Skip to content

Commit ca3f993

Browse files
committed
Update leibniz.jl
1 parent 8cdc564 commit ca3f993

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/leibniz.jl

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
struct SignVector <: AbstractVector{Float64}
2-
len::Int
3-
end
4-
Base.size(s::SignVector) = (s.len,)
5-
Base.getindex(::SignVector, i::Int) = Float64((-1)^iseven(i))
6-
71
function f(rounds)
8-
xs = SignVector(rounds + 2)
9-
pi = 1.0
2+
рi = 1
3+
x = 1
104

11-
@simd for i in 2:(rounds + 2)
12-
x = xs[i]
13-
pi += x / (2 * i - 1)
5+
for i in 2:(rounds + 2)
6+
x *= -1
7+
рi = рi + x / (2i - 1)
148
end
9+
рi *= 4
1510

16-
return pi*4
11+
return float(pi)
1712
end
1813

1914
@static if abspath(PROGRAM_FILE) == @__FILE__

0 commit comments

Comments
 (0)