dbTalk Databases Forums  

[BUGS] BUG #1577: round(dp) function does not round to nearest integer properly

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #1577: round(dp) function does not round to nearest integer properly in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Roman Schayuk
 
Posts: n/a

Default [BUGS] BUG #1577: round(dp) function does not round to nearest integer properly - 04-10-2005 , 02:21 PM







The following bug has been logged online:

Bug reference: 1577
Logged by: Roman Schayuk
Email address: rschayuk (AT) rogers (DOT) 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)

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] BUG #1577: round(dp) function does not round to nearest integer properly - 04-10-2005 , 02:59 PM






"Roman Schayuk" <rschayuk (AT) rogers (DOT) com> writes:
Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org


Reply With Quote
  #3  
Old   
Russell Smith
 
Posts: n/a

Default Re: [BUGS] BUG #1577: round(dp) function does not round to nearest integer properly - 04-10-2005 , 07:50 PM



On Mon, 11 Apr 2005 05:57 am, Tom Lane wrote:
Quote:
"Roman Schayuk" <rschayuk (AT) rogers (DOT) 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).

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)



Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Reply With Quote
  #4  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] BUG #1577: round(dp) function does not round to nearest integer properly - 04-11-2005 , 01:07 AM



Russell Smith <russell (AT) pws (DOT) com.au> writes:
Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.