Re: ROUND function ??

Поиск
Список
Период
Сортировка
От Allan Engelhardt
Тема Re: ROUND function ??
Дата
Msg-id 3BC3855A.9909FE71@cybaea.com
обсуждение исходный текст
Ответ на Re: ROUND function ??  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Tom Lane wrote:

> [...]Because the IEEE float math standard says so.  Round-to-nearest-even
> is considered good practice.

I learn something new every day.  :-)

While it is true that IEEE 754 defaults to "round-to-nearest", which means rounding midway points to even, it is
slightlyconfusing that this is implemented in the math library (libc) by the  rint  function (subject to compiler
defaultsand  fesetround  calls) while the  round  functions ((ll|l)?round(f|l)?) of the library does indeed 'round
half-waycases away from zero to the nearest integer', which is also the mathematical behavior.  Try
 
   % info libc Arithmetic Rounding   % info libc Arithmetic 'Arithmetic Functions' 'Rounding Functions'

on you local friendly U*ix clone and you shall find enlightenment...


The SQL standard seems to leave it implementation dependent ('92, sec 4.4.1):

        An approximation obtained by rounding of a numerical value N for        an <exact numeric type> T is a value V
representablein T such        that the absolute value of the difference between N and the nu-        merical value of V
isnot greater than half the absolute value        of the difference between two successive numerical values repre-
 sentable in T. If there are more than one such values V, then it is        implementation-defined which one is taken.
 


So PostgreSQL does "the right thing" (again!).


Allan.


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

Предыдущее
От: "Josh Berkus"
Дата:
Сообщение: Re: Loading current_user and current_timestamp using COPY
Следующее
От: Gerardo Perosio
Дата:
Сообщение: SELECT FOR UPDATE CLAUSE