Mitigate stack overflows?

A friend and I have written a basic Proth number tester that asks for k and an upper/lower bound of n, then tests with N=k*(2^n)-1 with a nice do-while loop.

That all works fine...unless we input an upper bound greater than 33 or so. I've yet to determine what exactly causes the program to hang, but it appears as though it cannot handle an N larger than 11 digits.

Quite an improvement over the previous version, which could not handle larger than (2^31)-1.

You can see our code here: http://code.google.com/p/gjsieve/source/browse/main_5.cpp

We believe it's a stack problem. I'm just not sure how to increase it properly. We were told to increase max stack size in linking options for the compiler, but that changed nothing.

If we try with k = 3, lower = 3, and upper = 33, it works fine. If we input 34 as the upper bound, it hangs and uses all available CPU...

What's going on, exactly?
Hmm, isn't your pow() calling itself recursively until a stack overflow occurs?
If you don't crash there, this could mean that you are actually using the standard pow() aznd not yours. And if your compiler chose the one with float arguments, the result range can not be very big (+-3.4E38 apparently).

Note that if you want to compute 2^N on integers, it can be obtained by (1ULL<<N). The ULL after the constant is to specify that you want a shift on a uint64 and not an as it would assume by default
Topic archived. No new replies allowed.