Re: integer square root function proposed

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: "Martin L(dot) Buchanan" <martinlbuchanan(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: integer square root function proposed
Date: 2022-12-18 03:56:16
Message-ID: 806b2307-31f8-5c1b-3503-de7d20ad282c@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/17/22 20:40, Martin L. Buchanan wrote:
> Dear Rob and all readers:
>
> Generating prime numbers is one example where you use integer square
> root in the inner loop, going from integer to integer.
>
> Calculating an integer square root from an integer input may have a
> more efficient algorithm than doing so in floating-point, with the
> caveat that an underlying processor architecture may provide
> floating-point square root instructions but not integer square root
> instructions. In that particular case an implementation could use the
> floating-point instructions internally.
>
> Some but not all programming languages provide isqrt
> directly, math.isqrt in Python or isqrt in Common Lisp for example.
>
> It would be a useful and convenient function and would not, I believe,
> impair the other features of PostgreSQL in any way.
>
> That said, as a PG novice (2+ years now), I completely defer to the
> greater wisdom of those much more involved in PostgreSQL. So something
> for you all to think about.
>

Seasons greetings to you and welcome to the list.  Here we generally
bottom post.

I have zero say in whether or not isqrt might get added to postgres but
in the meantime you might craft your own function (sql or plpgsql) which
does the necessary casting.  Or are you specifically after a faster
function?  And would a plpythonu function using their isqrt be fast
enough.  (Note the "u" in plpythonu means "untrusted")

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-12-18 04:20:45 Re: integer square root function proposed
Previous Message Martin L. Buchanan 2022-12-18 03:40:01 Re: integer square root function proposed