Re: Slaying the HYPOTamus - Mailing list pgsql-hackers

From Kevin Grittner
Subject Re: Slaying the HYPOTamus
Date
Msg-id 4A928BEE0200002500029FF2@gw.wicourts.gov
Whole thread Raw
In response to Re: Slaying the HYPOTamus  (David Fetter <david@fetter.org>)
Responses Re: Slaying the HYPOTamus  (David Fetter <david@fetter.org>)
List pgsql-hackers
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


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: DELETE syntax on JOINS
Next
From: Josh Berkus
Date:
Subject: Re: 8.5 release timetable, again