get rid of Abs()

From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: get rid of Abs()
Date: 2022-10-04 07:07:36
Message-ID: 4beb42b5-216b-bce8-d452-d924d5794c63@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I was wondering why we have a definition of Abs() in c.h when there are
more standard functions such as abs() and fabs() in widespread use. I
think this one is left over from pre-ANSI-C days. The attached patches
replace all uses of Abs() with more standard functions.

The first patch installs uses of abs() and fabs(). These are already in
use in the tree and should be straightforward.

The next two patches install uses of llabs() and fabsf(), which are not
in use yet. But they are in C99.

The last patch removes the definition of Abs().

Fun fact: The current definition

#define Abs(x) ((x) >= 0 ? (x) : -(x))

is slightly wrong for floating-point values. Abs(-0.0) returns -0.0,
but fabs(-0.0) returns +0.0.

Attachment Content-Type Size
0001-Remove-unnecessary-uses-of-Abs.patch text/plain 20.7 KB
0002-Use-llabs-instead-of-Abs-where-appropriate.patch text/plain 2.9 KB
0003-Use-fabsf-instead-of-Abs-where-appropriate.patch text/plain 2.1 KB
0004-Remove-Abs.patch text/plain 752 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2022-10-04 07:19:19 Re: log_heap_visible(): remove unused parameter and update comment
Previous Message Peter Smith 2022-10-04 07:01:16 Re: GUC tables - use designated initializers