Tasmota/lib/libesp32/Berry/examples/calcpi.be

17 lines
259 B
Plaintext
Raw Normal View History

2021-04-12 18:53:35 +01:00
def cpi(n)
i = 2
pi = 3
while i <= n
term = 4.0 / (i * (i + 1) * (i + 2))
if i % 4
pi = pi + term
else
pi = pi - term
end
i = i + 2
end
return pi
end
print("pi =", cpi(100))