Rounding incompatibility

Started by Havasvölgyi Ottóalmost 17 years ago5 messagesgeneral
Jump to latest
#1Havasvölgyi Ottó
havasvolgyi.otto@gmail.com

Hi,

I have found the following strangeness on Windows versions:

create table round_test (id int primary key, value double precision);
insert into round_test(id, value) values(1, 1.5);
insert into round_test(id, value) values(2, -1.5);
insert into round_test(id, value) values(3, 3.5);
select round(value) from round_test;

psql 8.2.13 returns

2
-2
4

But psql 8.3.3 returns

1
-1
3

Trying more values it seems that 8.2 rounding works according to banker's
rounding rules.
Can you confirm this?
How can I avoid this incompatibility or perhaps bug?

Thanks,
Otto

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Havasvölgyi Ottó (#1)
Re: Rounding incompatibility

=?ISO-8859-1?Q?Havasv=F6lgyi_Ott=F3?= <havasvolgyi.otto@gmail.com> writes:

I have found the following strangeness on Windows versions:

Were your two versions built different ways (perhaps with different
compilers)? This comes down to what the system-supplied rint() function
does.

regards, tom lane

#3Gurjeet Singh
singh.gurjeet@gmail.com
In reply to: Havasvölgyi Ottó (#1)
Re: Rounding incompatibility

On Mon, Jun 15, 2009 at 4:28 PM, Havasvölgyi Ottó <
havasvolgyi.otto@gmail.com> wrote:

Hi,

I have found the following strangeness on Windows versions:

create table round_test (id int primary key, value double precision);
insert into round_test(id, value) values(1, 1.5);
insert into round_test(id, value) values(2, -1.5);
insert into round_test(id, value) values(3, 3.5);
select round(value) from round_test;

psql 8.2.13 returns

2
-2
4

But psql 8.3.3 returns

1
-1
3

Trying more values it seems that 8.2 rounding works according to banker's
rounding rules.
Can you confirm this?
How can I avoid this incompatibility or perhaps bug?

Posting the output of 'select version()' from both the databases will help
blaming some distribution.

Best regards,
--
Lets call it Postgres

EnterpriseDB http://www.enterprisedb.com

gurjeet[.singh]@EnterpriseDB.com
singh.gurjeet@{ gmail | hotmail | indiatimes | yahoo }.com
Mail sent from my BlackLaptop device

#4Dave Page
dpage@pgadmin.org
In reply to: Tom Lane (#2)
Re: Rounding incompatibility

On Mon, Jun 15, 2009 at 3:33 PM, Tom Lane<tgl@sss.pgh.pa.us> wrote:

=?ISO-8859-1?Q?Havasv=F6lgyi_Ott=F3?= <havasvolgyi.otto@gmail.com> writes:

I have found the following strangeness on Windows versions:

Were your two versions built different ways (perhaps with different
compilers)?  This comes down to what the system-supplied rint() function
does.

If they are our packages, then 8.2 was built with mingw/msys, and 8.3 with VC++.

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com

#5Havasvölgyi Ottó
havasvolgyi.otto@gmail.com
In reply to: Dave Page (#4)
Re: Rounding incompatibility

Yes, they are both your packages from your official site. So this means that
in 8.2 and in earlier versions the rounding is not the regular one.

Best regards,
Otto

2009/6/15 Dave Page <dpage@pgadmin.org>

Show quoted text

On Mon, Jun 15, 2009 at 3:33 PM, Tom Lane<tgl@sss.pgh.pa.us> wrote:

=?ISO-8859-1?Q?Havasv=F6lgyi_Ott=F3?= <havasvolgyi.otto@gmail.com>

writes:

I have found the following strangeness on Windows versions:

Were your two versions built different ways (perhaps with different
compilers)? This comes down to what the system-supplied rint() function
does.

If they are our packages, then 8.2 was built with mingw/msys, and 8.3 with
VC++.

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com