From: | Paul Matthews <plm(at)netspace(dot)net(dot)au> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Slaying the HYPOTamus |
Date: | 2009-08-23 07:00:50 |
Message-ID: | 4A90E922.408@netspace.net.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Tom Lane wrote:
> Greg Stark <gsstark(at)mit(dot)edu> writes:
>
>> If there's a performance advantage then we could add a configure test
>> and define the macro to call hypot(). You said it existed before C99
>> though, how widespread was it? If it's in all the platforms we support
>> it might be reasonable to just go with it.
>>
>
> For one data point, I see hypot() in HPUX 10.20, released circa 1996.
> I suspect we would want a configure test and a substitute function
> anyway. Personally I wouldn't have a problem with the substitute being
> the naive sqrt(x*x+y*y), particularly if it's replacing existing code
> that overflows in the same places.
>
> regards, tom lane
>
>
A hypot() substitute might look something like this psudo-code, this is
how Python does it if the real hypot() is missing.
double hypot( double dx, double dy )
{
double yx;
if( isinf(dx) || ifinf(dy) ) {
return INFINITY;
}
dx = fabs(dx);
dy = fabs(dy);
if (dx < dy) {
double temp = dx;
dx = dy;
dy = temp;
}
if (x == 0.)
return 0.;
else {
yx = dy/dx;
return dx*sqrt(1.0+yx*yx);
}
}
As the following link shows, a lot of care could be put into getting a
substitute hypot() correct.
http://gforge.inria.fr/plugins/scmsvn/viewcvs.php/trunk/hypot.c?rev=5677&root=mpfr&view=markup
From | Date | Subject | |
---|---|---|---|
Next Message | Magnus Hagander | 2009-08-23 09:16:52 | Re: Slaying the HYPOTamus |
Previous Message | Tom Lane | 2009-08-23 05:57:34 | Re: 8.5 release timetable, again |