
/* Numerical integration of the integral from 1 to 2 */
/* of the function 1/x: the exact value is ln 2      */
/* Integration ??? */
/* with various choices of the discretization step h */

void main()
{
	float xnp1;
	float xn;
	float tn;
	float h;
	//float ln2;
	int nb_steps;
	int i;
	
	//ln2 = log(2.0); /* exact value */
	
	nb_steps = 1;
	while (nb_steps <= 1073741824)
	{
		h = 1.0 / (double)(nb_steps);
		
		tn=1.0; xn=0.0;
		for (i=0; i<nb_steps; i++)
		{
			xnp1 = xn + h/tn;
			tn += h; xn = xnp1;
		}
		
		//printf("Nb steps = %d, step size = %2.15f, error = %2.15f\n", nb_steps, h, ln2 - xn);
		if (nb_steps< 1073741824) nb_steps *=2; else nb_steps+=1;
	}
}
