I am trying to code an iterative function which takes an initial
double t = /*formula 1*/;
and then computes
for (auto i = 0; i < bigNumber; ++i)
{
temp = /*formula 2*/;
t = t*temp;
}
This works fine, except in the cases where the initial t
is so small that C++ automatically sets it equal to zero (it is NOT actually supposed to be zero).
Then of course t
will forever remain zero since we multiply it by itself, and that's the problem.
I tried solving this by setting t
equal to some very small, but non-zero, number in case C++ had set it to zero, but this doesn't work, because then, I end up with the opposite problem, as t
eventually blows up, once we have iterated it enough times.
How do I solve this problem?
Possibly worth mentioning:
The first formula (formula 1) involves stuff like exp(-verybignumber)
and the second formula involves stuff like pow(i, -1)
, meaning it becomes very small with higher iterations.