Search Postgresql Archives

Re: integer square root function proposed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Best wishes, Happy Channukah, and Merry Christmas,

Martin L. Buchanan
software developer and writer since 1976
Laramie, WY

On Sat, Dec 17, 2022 at 8:20 PM Rob Sargent <robjsargent@xxxxxxxxx> wrote:
On 12/17/22 19:39, Martin L. Buchanan wrote:
Dear PostgreSQL colleagues:

I have just joined this, my first PG mailing list.

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.

If PG leaders smile on this suggestion, could we have isqrt(foo) where foo has a numeric type and the result type is the same numeric type, with the result type being the integer square root for foo >= 0 and producing an error if negative? (And with infinities and NaNs processed as described in 8.1 Numeric Types).

I did not see an explicit enhancement request list in the PG mailing lists. Recommendations for a more specific list to post this to are welcome.



I suspect the majority are comfortable getting a non-integer result for the square root of a number.  What environment have you which needs (sqrt(a) * sqrt(a)) < a-epsilon?


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux