get rid of Abs()

Peter Eisentraut <peter.eisentraut@enterprisedb.com>

From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2022-10-04T07:07:36Z
Lists: pgsql-hackers

Attachments

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.

Commits

  1. Remove Abs()

  2. Use C library functions instead of Abs() for int64

  3. Use fabsf() instead of Abs() or fabs() where appropriate

  4. Remove unnecessary uses of Abs()