clear
// 格雷果里-莱布尼茨级数
// 收敛速度很慢
pi  call calc_pi0630 )

end

calc_pi:
    
prompt off
    
local iter

    
iter    getpara

    
local number
    
local sig       // 0 - sub, 1 - add
    
local kkk       // 3, 5, 7, 9 ...
    
local prod      // 3 * 5 * 7 * 9 ...
    
local tmp
    
local result

    
number  04
    
sig     00
    
kkk     01    // x = x + 2, the x = 3, 5, 7, 9
    
prod    01

    
times   00

again:

    
kkk     big_add$kkk02 )
    
prod    big_mul$prod$kkk )

    
tmp     big_div$prod$kkk )
    
tmp     big_mul$tmp04 )
    
number  big_mul$number$kkk )

    
if $sig == 00
        
number  big_sub$number$tmp )
        
sig     01
//      ? " - 4 / " int( 0x$kkk )
    
else
        
number  big_add$number$tmp )
        
sig     00
//      ? " + 4 / " int( 0x$kkk )
    
endif


    
times   big_add$times01 )

    
if $times < $iter
        
goto again
    
endif

    
// 前面生成的是pi * prod,下面要还原
    
// 又因为只支持整数除法,所以乘以多个10,用于将小数转成整数
    
do 15
        
number  big_mul$number0a )
    
loop

    
result  big_div$number$prod )
    
result  hex2int$result )        // 转成10进制数进行显示
    
prompt on
return $result