The Time Value of Money
An Introduction |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
low = a lower bound
high = an upper bound
while (high and low are too far apart)
{
guess = (low + high) / 2.0
calculate the PV for flow using guess
if (PV > 0.0) // guess is too low
{
low = guess;
}
else if (PV < 0.0) // guess is too high
{
high = guess;
}
else // guess is just right
{
low = high = guess;
}
}
return (low + high)/2.0