Re: Remove dependence on integer wrapping

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Joseph Koshakow <koshy44(at)gmail(dot)com>
Cc: Alexander Lakhin <exclusion(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Remove dependence on integer wrapping
Date: 2024-07-16 17:57:47
Message-ID: Zpa0m_OVw_iWYicV@nathan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jul 15, 2024 at 07:55:22PM -0400, Joseph Koshakow wrote:
> On Mon, Jul 15, 2024 at 11:31 AM Nathan Bossart <nathandbossart(at)gmail(dot)com>
> wrote:
>> I'm curious why you aren't using float8_mul/float8_div here, i.e.,
>>
>> fresult = rint(float8_mul((float8) c, f));
>> fresult = rint(float8_div((float8) c, f));
>
> I wrongly assumed that it was only meant to be used to implement
> multiplication and division for the built-in float types. I've updated
> the patch to use these functions.

The reason I suggested this is so that we could omit all the prerequisite
isinf(), isnan(), etc. checks in the cash_mul_float8() and friends. The
checks are slighly different, but from a quick glance it just looks like we
might end up relying on the FLOAT8_FITS_IN_INT64 check in more cases.

>> and "cash_sub_int64"
>
> Did you mean "cash_div_int64"? There's only a single function that
> subtracts cash and an integer, but there's multiple functions that
> divide cash by an integer. I've added a "cash_div_int64" in the updated
> patch.

My personal preference would be to add helper functions for each of these
so that all the overflow, etc. checks are centralized in one place and
don't clutter the calling code. Plus, it might help ensure error
handling/messages remain consistent.

+static Cash
+cash_mul_float8(Cash c, float8 f)

nitpick: Can you mark these "inline"? I imagine most compilers inline them
without any prompting, but we might as well make our intent clear.

--
nathan

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Aleksander Alekseev 2024-07-16 18:14:35 Re: [PATCH] Refactor pqformat.{c,h} and protocol.h
Previous Message Tomas Vondra 2024-07-16 17:54:32 Re: Differents execution times with gin index, prepared statement and literals.