Re: [HACKERS] pow support for pgbench - Mailing list pgsql-hackers

From Raúl Marín Rodríguez
Subject Re: [HACKERS] pow support for pgbench
Date
Msg-id CAM6_UM45MSRq_2MDfCOEFwjA0-NYzJLe11-sKgF7ZfncErTPgw@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] pow support for pgbench  (Fabien COELHO <coelho@cri.ensmp.fr>)
List pgsql-hackers
Hi Fabien,

Thanks for the review.
I've fixed the documentation and added an ipow function that handles both 
positive and negative ints, having 0^0 == 1 and 0^(negative) == PG_INT64_MAX
since that's what my glibc math.h pow() is returning.

On Sat, Nov 4, 2017 at 12:34 PM, Fabien COELHO <coelho@cri.ensmp.fr> wrote:

Hello Raúl,

Sorry about the patch. Attaching it now so it can be considered as
submitted.

There is a typo in the XML doc:

        <literal>1024.0/<literal>

Please check that the documentation compiles.

I'm at odds with having the integer version rely on a double pow(), even if it works. I think that there should be a specific integer version which does use integer operations. From stack overflow, the following is suggested:

 int ipow(int base, int exp)
 {
    int result = 1;
    while (exp)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        base *= base;
    }

    return result;
 }

The integer version should be when x & y are integers *AND* y >= 0.

if y is a negative integer, the double version should be used.

--
Fabien.



--
Raúl Marín Rodríguez
carto.com

Attachment

pgsql-hackers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: [HACKERS] Display number of heap accesses for index scans
Next
From: "MauMau"
Date:
Subject: Re: [HACKERS] Statement-level rollback