BUG #1577: round(dp) function does not round to nearest integer properly
The following bug has been logged online:
Bug reference: 1577
Logged by: Roman Schayuk
Email address: rschayuk@rogers.com
PostgreSQL version: 7.2.2
Operating system: RedHat Linux 8.0 x86
Description: round(dp) function does not round to nearest integer
properly
Details:
SQL command:
gap=> select round(42.5);
round
-------
42
(1 row)
Result has to be 43
In contrast round(numeric, int) function works properly:
gap=> select round(42.5,0);
round
-------
43
(1 row)
"Roman Schayuk" <rschayuk@rogers.com> writes:
gap=> select round(42.5);
round
-------
42
(1 row)
Result has to be 43
No, the above is perfectly correct and in fact required by the IEEE
standard for floating-point arithmetic (because round-to-nearest-even
is the default rounding mode).
If anything needs to be changed here, it's the behavior of round(numeric).
regards, tom lane
On Mon, 11 Apr 2005 05:57 am, Tom Lane wrote:
"Roman Schayuk" <rschayuk@rogers.com> writes:
gap=> select round(42.5);
round
-------
42
(1 row)
Result has to be 43No, the above is perfectly correct and in fact required by the IEEE
standard for floating-point arithmetic (because round-to-nearest-even
is the default rounding mode).
That is rounding of unrepresentable numbers, is it not? at least
http://www.ee.ucla.edu/~vandenbe/103/flpt.pdf suggests that to me as I couldn't find
the IEEE spec about this. I'm sure somebody has it at hand, but I don't.
Either way 8.0.1 round differently;
test=# select version();
version
--------------------------------------------------------------------------------------------------------------------------
PostgreSQL 8.0.1 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3.2 20031218 (Gentoo Linux 3.3.2-r5, propolice-3.3-7)
(1 row)
test=# select round(42.5);
round
-------
43
(1 row)
test=# select round(42.5,0);
round
-------
43
(1 row)
If anything needs to be changed here, it's the behavior of round(numeric).
So I would say that the round behaviour has changed as Tom has suggested, but which is correct?
7.2, or 8.0?
Regards
Russell Smith
Russell Smith <russell@pws.com.au> writes:
Either way 8.0.1 round differently;
The rounding is the same. The difference from 7.2 is that the unadorned
literal "42.5" is now considered to be numeric whereas 7.2 treated it as
float8. This changed quite some time ago (in 7.3 it looks like).
regards, tom lane