Created
March 21, 2019 16:46
-
-
Save ccamel/4ce87632e3ac1f20748015baf864722c to your computer and use it in GitHub Desktop.
Computation of π with PostgreSQL Recursive Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- just for fun | |
-- compute π using the Leibniz formula | |
with recursive leibniz (n, r) as ( | |
select 0, 0. | |
union | |
select n + 1, r + cast(power(-1, n) as decimal) / (2. * n + 1.) | |
from leibniz | |
where n < 10000 | |
) | |
select 4. * r as pi from numbers offset 10000; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment