calculate pi using James Gregory's formula