Re: numeric and float converts to int differently?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: numeric and float converts to int differently?
Дата
Msg-id 23857.1067358382@sss.pgh.pa.us
обсуждение исходный текст
Ответ на numeric and float converts to int differently?  ("SZŰCS Gábor" <surrano@mailbox.hu>)
Список pgsql-sql
"SZŰCS Gábor" <surrano@mailbox.hu> writes:
> QUESTION 1: Is it intentional that converting 0.5 to int4
> - from numeric: rounds *away from* zero
> - from float: rounds *towards* zero (tried float4 and float8 too)?

Numeric currently rounds away from zero.  We cannot guarantee to make
it work the same as float, because float's rounding behavior is
platform-dependent.  A common but not universal behavior is "round to
nearest even integer".  See the recent thread about the round() function
(I forget which list it was in, but it was within the past week).

> QUESTION 2: Is it safe to assume it won't change (haven't changed) in the
> upcoming versions?

Numeric's behavior hasn't changed as of 7.4beta5.  I do not have a
crystal ball to predict whether we might change it in the future.
I doubt we will ever try to override the platform behavior for float.
        regards, tom lane


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: bug in working with TEXT constants ?
Следующее
От: "SZŰCS Gábor"
Дата:
Сообщение: Re: numeric and float converts to int differently?