Re: Minor bug in src/port/rint.c

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Minor bug in src/port/rint.c
Дата
Msg-id 13697.1200865674@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Minor bug in src/port/rint.c  (Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>)
Ответы Re: Minor bug in src/port/rint.c  (Magnus Hagander <magnus@hagander.net>)
Re: Minor bug in src/port/rint.c  (Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>)
Список pgsql-hackers
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:
> I believe that there is a small bug in src/port/rint.c when the input
> parameter has a fractional part of 0.5 which is demonstrated by the
> attached program. It appears that the PG version of rint() rounds in the
> wrong direction with respect to glibc.

> The fix is, of course, to add an equals into the if() comparisons on
> lines 21 and 26, so that when the fractional part is 0.5, it rounds in
> the opposite direction instead.

Your proposed fix wouldn't make it act the same as glibc, only move the
differences around.  I believe glibc's default behavior for the
ambiguous cases is "round to nearest even number".  You propose
replacing "round towards zero", which is what our code currently does,
with "round away from zero", which really isn't likely to match any
platform's behavior.  (The behaviors specified by IEEE are "to nearest
even", "towards zero", "towards minus infinity", and "towards plus
infinity", with the first being the typical default.)

Considering that probably every modern platform has rint(), I doubt
it's worth spending time on our stopgap version to try to make it
fully IEEE-compliant ...
        regards, tom lane


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

Предыдущее
От: Teodor Sigaev
Дата:
Сообщение: Re: message string fixes
Следующее
От: Tom Lane
Дата:
Сообщение: Re: message string fixes