Last active
March 13, 2021 23:28
-
-
Save BBI-YggyKing/9d8e30ea57851268b92314b4d2e6dc74 to your computer and use it in GitHub Desktop.
Happy π Day!
This file contains hidden or 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
@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