Out of range

1
2
3
4
5
6
    x = k*s;
    while (x > n)
    {  
        x = floor(( k*(x-n) - 1.0 )/ (k-1.0) );
        count++;
    }


In the above code n, k, s integers <= 1000000. Whenver x goes out of range of integer it gives me wrong output. I tried making it unsigned long long but still I am getting wrong answer. Can someone help me out in this?

Thanks in advance
If n, k, and s are all integers, why do I see a floor() function and floating point constants? Why not use integer math?

If you need the large numbers then you probably need to look at a multi-precicsion library (such as http://gmplib.org/).

Is x an integer? What about count?
Earlier I was working with double values, so that floor was for that purpose. I can remove floor, not a big deal and other non-integer values.

Yes x and count are integers as well. Why is it not working with unsigned long long data type?
When you say it is not working, what does that mean?

Show us a table of the values of x, k, s, & n for a few iterations before the problem and then when the problem appears.
Problem Solved.

Though x was unsigned long since k and s were integers, they were being saved in an intermediate integer variable and was then converted to unsigned long. Hence wrong result. Now its correct.

Thanks once again
Topic archived. No new replies allowed.