David Fetter <david@fetter.org> wrote:
> On Mon, Aug 24, 2009 at 11:14:19PM +1000, Paul Matthews wrote:
> These next two lines are a teensy bit baroque. Is there some
> significant speed increase that would justify them?
>
>> if (x == 0.0)
>> return 0.0;
>> else {
>> yx = y/x;
>> return x*sqrt(1.0+yx*yx);
>> }
>> }
I think the reason is overflow. From the function comment:
>> * The traditional formulae of x^2+y^2 is rearranged
>> * to bring x outside the sqrt. This allows computation of the
hypotenuse
>> * for much larger magnitudes than otherwise normally possible.
Although I don't see why the first part isn't: if (y == 0.0) return x;
-Kevin