Re: get rid of Abs()

From: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Subject: Re: get rid of Abs()
Date: 2022-10-04 09:04:08
Message-ID: ea20c748-8d7b-4f43-a46a-0db873cddee1@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Oct 4, 2022, 15:07 +0800, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, wrote:
> 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.
+1,

Like patch3, also found some places where could use fabsf instead of fabs if possible, add a patch to replace them.

Regards,
Zhang Mingli

Attachment Content-Type Size
v2-0005-replace-fabs-with-fabsf-if-possible.patch application/octet-stream 1.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2022-10-04 09:28:57 Re: Add LSN along with offset to error messages reported for WAL file read/write/validate header failures
Previous Message bt22nakamorit 2022-10-04 08:41:12 JUMBLE_SIZE macro in two files