Skip to content

Instantly share code, notes, and snippets.

@BBI-YggyKing
Last active March 13, 2021 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BBI-YggyKing/9d8e30ea57851268b92314b4d2e6dc74 to your computer and use it in GitHub Desktop.
Save BBI-YggyKing/9d8e30ea57851268b92314b4d2e6dc74 to your computer and use it in GitHub Desktop.
Happy π Day!
@echo off
REM https://www.mathscareers.org.uk/calculating-pi
setlocal
set /A "U=1<<27"
set I=1
set /A P=3*U
set Q=0
:start
set /A D=(I*2)*(I*2+1)*(I*2+2)
set /A T=4*U/D
set /A M=I%%2
if %M%==0 (set /A P=P-T) else (set /A P=P+T)
set /A I=%I%+1
if %P% neq %Q% set Q=%P% & goto :start
set /A T=U
set H=.
<nul set /P=PI is approximately
:write
set /A D=P/U
<nul set /P=%D%%H%&set H=
set /A P=(P-D*U)*10
set /A T=T/10
if %T% gtr 0 goto :write
echo (after %I% Nilakantha terms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment