### Floating point numbers / numerical analysis

Hi,

I have the problem of trying to find the smallest natural number that makes two consecutive terms in single precision floating point notation in the riemann zeta function equal. So basically the riemann function of 2 is given by:

sum of 1/(k^2) from k=1 until infinity, so : 1/(1^2) + 1/(2^2) + 1/(3^2) + ...... until infinity.

Now the question asks to stop at the smallest natural number n, at which the sum 1/1^2 + 1/2^2 + ......+ 1/(n^2) is equal to the sum 1/1^2 + 1/2^2 + ..... + 1/((n+1)^2) in single precision floating point notation.

Now well the obvious way to look for n would be on this way:

 ``12345678`` `````` float i = 1.0; float n = 1/(i); float n1 = 1/(i+1.0); while ( n != n1){ i += 1.0; n = 1/i; n1 = 1/(i+1.0);}``````

But first of all this is obviously completely inefficient and I dont think it will yield a valid answer for any float variable, i.e. I dont think the sum until 1/n^2 and 1/(n+1)^2 will ever differ. I tried it out with the largest possible value of a variable of type float and the values were still seen as unequal in C++. Does anybody have an idea how to do this? Will C++ find a value for n for which the condition holds? Is the compiler or my hardware important for this, i.e. would I get different results on a different pc?

Last edited on
You are misunderstanding the problem

the smallest natural number n, at which the sum (to n) is equal to the sum (to n+1)
Thanks for pointing that out.^^ No idea what I was doing there.
Topic archived. No new replies allowed.