Re: BUG #17546: power() function - value is distorted via automatic type cast

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #17546: power() function - value is distorted via automatic type cast
Дата
Msg-id 1119193.1657554589@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #17546: power() function - value is distorted via automatic type cast  (PG Bug reporting form <noreply@postgresql.org>)
Список pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> When a certain number (p, s) with a fractional part (specific examples -
> 1.11 and 69.96) is multiplied by a power (10, N), the resulting value is
> distorted.
> However, if the power(10, N) is manually converted to an integer, the
> resulting value is correct.
> It looks like there is some kind of problem with the automatic type
> conversion of the power() function.

Your query is invoking the float8 variant of power(), which is
necessarily of limited precision.  If I change "w.degree::integer"
to "w.degree::numeric", then it invokes the numeric variant of
power(), and I get correctly rounded results (much more slowly
unfortunately :-().  So I don't see any bug here.

It might be surprising that the parser prefers float8 over numeric
when the given function arguments don't exactly match either one.
But that's a very ancient decision that we're not going to change.
There is support for it in the SQL standard, which directs
implementations to prefer inexact numeric types over exact ones
when they have to make a choice.

            regards, tom lane



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

Предыдущее
От: PG Bug reporting form
Дата:
Сообщение: BUG #17546: power() function - value is distorted via automatic type cast
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #17546: power() function - value is distorted via automatic type cast