Re: pow support for pgbench

Fabien COELHO <coelho@cri.ensmp.fr>

From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Raúl Marín Rodríguez <rmrodriguez@carto.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>, Michael Paquier <michael.paquier@gmail.com>, PostgreSQL mailing lists <pgsql-hackers@postgresql.org>
Date: 2017-11-04T11:34:52Z
Lists: pgsql-hackers
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.

Commits

  1. Add pow(), aka power(), function to pgbench.

  2. pgbench: Support double constants and functions.