Re: integer square root function proposed

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: integer square root function proposed
Дата
Msg-id 157202.1671337245@sss.pgh.pa.us
обсуждение исходный текст
Ответ на integer square root function proposed  ("Martin L. Buchanan" <martinlbuchanan@gmail.com>)
Список pgsql-general
"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



В списке pgsql-general по дате отправления:

Предыдущее
От: Rob Sargent
Дата:
Сообщение: Re: integer square root function proposed
Следующее
От: Thomas Boussekey
Дата:
Сообщение: Re: Autovacuum on sys tables