pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: Martin L. Buchanan <martinlbuchanan@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: integer square root function proposed
Date: Sat, 17 Dec 2022 20:56:16 -0700
Message-ID: <806b2307-31f8-5c1b-3503-de7d20ad282c@gmail.com> (raw)
In-Reply-To: <CAPfd9M=qBH0BKFs6ySnBnovG3=4wOVXcT1N1bnE7f6e+_N_usQ@mail.gmail.com>
References: <CAPfd9Mm5rh3TfW_frM4q7tmidM39_ezBQuYJXXf8ff6Y8_jSCQ@mail.gmail.com>
	<a6c1675b-4ca9-69f6-ec6e-3cdebab59d25@gmail.com>
	<CAPfd9M=qBH0BKFs6ySnBnovG3=4wOVXcT1N1bnE7f6e+_N_usQ@mail.gmail.com>

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")

view thread (5+ messages)  latest in thread

Message-ID: <806b2307-31f8-5c1b-3503-de7d20ad282c@gmail.com>
Permalink:  ../806b2307-31f8-5c1b-3503-de7d20ad282c@gmail.com/
Also on:    postgresql.org/message-id/806b2307-31f8-5c1b-3503-de7d20ad282c@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: robjsargent@gmail.com, martinlbuchanan@gmail.com
  Subject: Re: integer square root function proposed
  In-Reply-To: <806b2307-31f8-5c1b-3503-de7d20ad282c@gmail.com>
  References: <CAPfd9Mm5rh3TfW_frM4q7tmidM39_ezBQuYJXXf8ff6Y8_jSCQ@mail.gmail.com> <a6c1675b-4ca9-69f6-ec6e-3cdebab59d25@gmail.com> <CAPfd9M=qBH0BKFs6ySnBnovG3=4wOVXcT1N1bnE7f6e+_N_usQ@mail.gmail.com> <806b2307-31f8-5c1b-3503-de7d20ad282c@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox