Re: remove the unneeded header file math.h in binaryheap.c - Mailing list pgsql-hackers

From Álvaro Herrera
Subject Re: remove the unneeded header file math.h in binaryheap.c
Date
Msg-id 202601151607.75wqut3v2vvf@alvherre.pgsql
Whole thread Raw
In response to Re: remove the unneeded header file math.h in binaryheap.c  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
On 2026-Jan-15, Andres Freund wrote:

> Hi,
> 
> On 2026-01-15 23:08:28 +0800, zengman wrote:
> > I removed the <math.h> include from two files `dt_common.c` and
> > `timestamp.c`, and the code compiles successfully in my environment.
> > Would you consider adding this to the patch?

I would rather not touch ecpg.  (I skipped those files purposefully.)

> Just because removing a platform include file works in some environment is
> *NOT* sufficient to remove platform include files. There are a lot of
> variations between platforms about when some include files are implicitly
> included via other include files. Just removing them because it works on one
> platform ends up with more niche operating systems failing to build, which we
> may only figure out months or even years down the road.
> 
> At the very least you need to figure out why the includes where added and why
> that reason is not present anymore.

I'm willing to bet that a few of those (looking at contrib_gist) were
just bogus back then, because there was no sane rule being kept,
especially btree_gist.h was a mess.  Links
postgr.es/c/a22d76d96ada
https://www.postgresql.org/message-id/flat/Pine.BSO.4.63.0607132104010.30094%40leary2.csoft.net
postgr.es/c/66c15dfda1a7

Some others appear to be misunderstandings -- (e.g. intarray, ltree) use
abs() which is in stdlib.h (included by c.h) rather than math.h, as
fabs() is.   c.f. commit f14aad5169ba.

The change in segparse.y is a mistake.  That one uses HUGE_VAL and so it
needs math.h.

vacuumlazy.c had it by 5374d097de4d which added ceil().  No longer used.

xlogrecovery.c got it in 70e81861fadd as it was split from xlog.c (which
used ceil() itself).  Not really needed.

xlogwait.c is new; has never needed it.  Copy-pasto from xlog.c perhaps?
(Tested by adding #define _MATH_H and verifying that it still compiles.)

define.c got it in 7385619f14ec.  It used pow().  No longer (was removed
in 6eb8d255d217).

nodeBitmapHeapscan.c got it in c29aff959dc6.  Used rint().  No longer
(was removed in b09ff53667ff).

nodeSubplan.c got it in ae643747b16a.  Used ceil().  No longer (removed
in 299d1716525c).

knapsack.c got it at creation in b5635948ab16.  Unclear why.  I suspect
it was made unnecessary during development but not removed.

readfuncs.c got it at the beginning of time in d31084e9d11.  Maybe
because of atoi / atof / atol?  Completely different file nowadays.

GEQO got it at creation in 29138eeb3ca2.  Used ceil().  No longer.
geqo_pool.c doesn't appear to have needed it, probably just careless
development.

indxpath.c got it at down of time in d31084e9d11.  I'm betting it wasn't
needed then, as it isn't now.

joinpath.c got it then too.  It used ceil()/sqrt().  No more (removed in
c2f0d565f319).

createplan.c got it in 2c2161a47d47.  Used rint(). Was removed in
8c314b9853c2.

pathnode.c got it in d31084e9d11.  Used pow().  Was removed in
166b5c1def56.

mcv.c got it at creation in 7300a699502f.  Cargo-culted?  (sqrt is used
in comments, maybe the actual call was removed during development?).
This code was written by a mathematician, maybe they're a fan of math.h.

numutils.c got it in d31084e9d11.  Used pow().  No longer.  Code is
completely unrelated nowadays.

tid.c got it pointlessly in 7aee5ed3b73f.  It added calls to strtol and
strtoul, which are in stdlib.h, not math.h.  Shrug.

binaryheap.c was already explained.

date.h got it as part of a22d76d96ada.  It had rint(), was removed by
b9d092c962ea.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: how to gate experimental features (SQL/PGQ)
Next
From: Corey Huinker
Date:
Subject: Re: Import Statistics in postgres_fdw before resorting to sampling.