Slaying the HYPOTamus

From: Paul Matthews <plm(at)netspace(dot)net(dot)au>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Slaying the HYPOTamus
Date: 2009-08-23 03:54:30
Message-ID: 4A90BD76.7070804@netspace.net.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Like some ancient precursor to the modern hypot()enuse the dreaded
ill-tempered HYPOT()amus lurks in the recesses of geo_ops.c and
geo_decls.h. And many a line of code has been swallowed by its mighty maw.

This patch replaces the HYPOT() macro with a calls to the hypot() function.

The hypot() function has been part of the C standard since C99 (ie 10
years ago), and in most UNIX, IBM and GNU libraries longer than that.
The function is designed not to fail where the current naive macro would
result in overflow. Where available, we might expect to the hypot()
function to take advantage of underlying hardware opcodes. In addition
the function evaluates its arguments only once. The current macro
evaluates its arguments twice.

Currently
HYPOT(a.x - b.x, a.y - b.y))
becomes:
sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y) * (a.y - b.y))

The patch passes all test.

Patch attached below. (First attempt at using CVS. Hope it's all good)

Attachment Content-Type Size
patchfile text/plain 5.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2009-08-23 03:58:01 Re: BUG #4996: postgres.exe memory consumption keeps going up
Previous Message Craig Ringer 2009-08-23 03:48:00 Re: BUG #4996: postgres.exe memory consumption keeps going up