> ...

> > A few notes on the program Pete's presented here earlier:

> > It finds the infinite sum in the form

> > s = SUM(i=0,...,inf) 2**(-i)

> > or

> > s = 1 + 0.5 + 0.25 + 0.125 + ...

> > This sum rapidly converges (and its limit is certainly

> > well known, it is equal to 1/(1-0.5) = 2, see below) and in

James,

Quote:> That sum certainly converges; the question is whether that sum

> correctly describes what the code does.

Excellent observation, however my assumption was that the code

had been written with the intention to compute that sum. I might

be wrong in this...

Quote:> Pete is suggesting that if

> round-to-infinity mode is in effect, then the division by 2 will cease

> to cut the magnitude of the argument in half each time. If delta has

> shrunk down to the smallest representable positive floating point

> value, then delta/2.0 == delta, and from that point on the sum is over

> a constant value.

Yes, very much so if two conditions are met: round up mode and delta(i) > 0.

I posted a correction to my first post to the thread, where I claimed

that (new_float != old_float) is not a save condition.

Quote:> Also because of the rounding mode, new_float+delta > old_float,

Yes very much so, if two previous condition are valid plus

old_float and new_float both > 0.

Quote:> even when delta<old_float*DBL_EPSILON, and that will make

> the sum start differing from your formula long before

> (delta/2)==delta. Therefore, the sum would not terminate until it

> overflows.

I am afraid I do not follow you in this. The condition for terminating

the loop I had suggested was (delta >= new_float*EPSILON). Essentially,

the loop terminates as soon as delta is small in comparison with new_float.

As you noticed, (delta/2)==delta when delta is the smallest representable

number. The condition I suggested stops the iterations when delta is

on the order of 2*macheps which is much much larger than the smallest

representable number.

It works for this particular algorithm in any rounding mode for either

precision, and ensures that the loop calculates the correct result within

machine relative error bounds.

Rgds,

Andrew