floating point shenanigans

I have a newton raphson loop where I have the following:

lambda -= delta;

typically, I have to do an operation such as:

lambda = 52347.592
delta = 0.001542

and then I end up with terribad floating point rounding errors since floating point operations can only support approximately 7 significant digits.

I’d very much prefer to stay away from doubles if possible due to its terrible floating point performance.

edit: after some more investigation - seems like I need to change a lot of floats to doubles - give me a 50% penalty in running time… sigh.

Apparently doubles run at 1/10th the speed of single precision floats

You could try something of the form:

lambda = lambda0 - iteration*delta;

Where lambda0 in the initial value for lambda and iteration is the iteration count. This will get rid of cumulative error.