# How can I get the value of in a loop?

```
let pi_2 iters =
let rec loop_ a b t p i =
if i = 0 then a,b,t,p
else
let a_n = (a +. b) /. 2.0
and b_n = sqrt (a*.b)
and p_n = 2.0 *. p in
let t_n = t -. (p *. (a -. a_n) *. (a -. a_n)) in
loop_ a_n b_n t_n p_n (i - 1)
in
let a,b,t,p = loop_ (1.0) (1.0 /. (sqrt 2.0)) (1.0/.4.0) (1.0) iters in
(a +. b) *. (a +. b) /. (4.0 *. t)
```

```
int 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);}
```

Tags: language-agnostic unix algorithm performance pi

Source: By Chris Jester-Young as answer to the question

This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 4.0

##### Related code-snippets:

- Is gettimeofday() guaranteed to be of microsecond resolution?
- Anatomy of a memory leak -'memory leak'
- Function for creating color wheels.
- Why use unsigned values over signed ones?
- Generate list of all possible permutations of a string.
- How can I use combinations of sets as test data?
- What is the most efficient code for 10000 prime numbers?
- Format string to title case. Title case is a common text format in English.
- How can I create an object instance from a Type?
- How can we efficiently get sorted sums of a sorted list?
- How can I make my projects international in india?
- How do I get root permission for my file inside vi?
- A little diversion into floating point (im)precision, part 1 | 1 – 0 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 1 | 2 | 1 | 2 | 1 | 1 | 2 | 1 | 2 | 3 | 4 | A little diversion into floating point (im)precision, part 1 | 3 | 4 | 5 | 5 | 8 | 8 | 2 | 3 | 4 | 7 | 8 | 7 | 7 | 7 | 6 | 1 | 1 | 5 | 1
- I am using the directx x or opengl to create 100 floating cubes. Is this possible?
- How is database indexing used?