Accurate calculation of 800 decimals after PI decimal point

xiaoxiao2021-03-06  64

Recently, I found a C pro program that can accurately calculate hundreds of CIs after PI, I don't dare to translate it into a Pascal version. For your reference, the function writes very delicate, only three lines of code, you can Accurate calculation of 800 decimals after PI. The younger brother is not talented, not deep to mathematics, do not understand what the principle of his algorithm is, if you have understandable, please do not give us a regulation. The C version of this function is also posted by one of the C & Pascal version for your reference.

//// C language source program function: Accurate calculation of Pi decimal point 799 decimal // from http://www.programfan.net/club/showbbs.asp?id=16434//// #include

// #include

// long a = 10000, b, c = 2800, d, e, f [2801], g;

// main ()

// {

// for (; b-c;) F [b ] = a / 5;

// for (; D = 0, g = c * 2; c- = 14, printf ("%. 4D", E D / A), E = D% a)

// for (b = C; D = f [b] * a, f [b] = D% - g, d / = g -, - b; D * = b);

//}

///

// All rights reserved, please indicate the source

// This C function Delphi version

// Compilation: Huang Tao

Hunter@shentong.com.cn

// 2004-9-7

Function Calcpi: String;

// long a = 10000, b, c = 2800, d, e, f [2801], g;

VAR A, B, C, D, E, G: Integer;

f: array [0..2800] of integer;

Begin

A: = 10000; B: = 0; C: = 2800; E: = 0; F [2800]: = 0;

// for (; b-c;) F [b ] = a / 5;

While (b-c) <> 0 do begin f [b]: = a DIV 5; Inc (b) end;

//for (4, 4 ,Printf ("%.4d" ,e d/a) ,e) ,e=d%a)

While C <> 0 do begin

D: = 0; g: = c * 2; b: = C;

Repeat

// for (b = C; D = f [b] * a, f [b] = D% - g, d / = g -, - b; D * = b);

D: = D F [b] * a; dec (g); f [b]: = D mod g;

D: = D DIV G; DEC (g); DEC (b);

IF B <> 0 THEN D: = D * B;

Until b = 0;

C: = C-14;

Result: = Result Format ('%. 4D', [E D DIV A]);

E: = D mod a;

END;

END;

As can be seen from the above code, the C language is very flexible, the code writes is indeed very refined, but his programming style is really not advocated, it is too difficult to understand, it is difficult to understand what he wrote. However, if anyone can write more refined Delphi code, please post for everyone to learn. I wrote just for translation, basically one, no more optimization.

转载请注明原文地址:https://www.9cbs.com/read-119162.html

New Post(0)