From: Tom Lane <tgl@sss.pgh.pa.us>
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 23:20:45 -0500
Message-ID: <157202.1671337245@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPfd9Mm5rh3TfW_frM4q7tmidM39_ezBQuYJXXf8ff6Y8_jSCQ@mail.gmail.com>
References: <CAPfd9Mm5rh3TfW_frM4q7tmidM39_ezBQuYJXXf8ff6Y8_jSCQ@mail.gmail.com>
"Martin L. Buchanan" <martinlbuchanan@gmail.com> writes:
> Reading the documentation I found no built-in function for integer square
> root, requiring a sequence of:
> floor(sqrt(foo))::integer
> to go from an integer to the integer square root as an integer.
I'm a little down on this idea, mainly because I doubt there is any
principled argument as to whether the rounding ought to be down, up,
or to nearest. Specific applications probably want a specific one
of those, but how likely is it that a built-in choice would satisfy
many users?
I'm not buying the performance angle too much either. Even granting
that your platform has an integer square root instruction that's faster
than its floating-point one, and that we can get at that from C, the
difference would likely be swamped by the overhead of the SQL function
call.
> (And with infinities and NaNs processed as described in
> 8.1 Numeric Types).
Our integers do not have infinities, nor NaNs.
Anyway, I don't mean to slam the door on this idea completely,
but I think you need to make a much better-supported argument
for it.
regards, tom lane
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: tgl@sss.pgh.pa.us, martinlbuchanan@gmail.com
Subject: Re: integer square root function proposed
In-Reply-To: <157202.1671337245@sss.pgh.pa.us>
References: <CAPfd9Mm5rh3TfW_frM4q7tmidM39_ezBQuYJXXf8ff6Y8_jSCQ@mail.gmail.com> <157202.1671337245@sss.pgh.pa.us>
* 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