pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: He Weiping(Laser Henry) <laser@zhengmai.com.cn>
Cc: pgsql-docs@postgresql.org
Subject: Re: some errors and/or bugs?
Date: Mon, 18 Dec 2000 20:02:49 -0500
Message-ID: <2639.977187769@sss.pgh.pa.us> (raw)
In-Reply-To: <3A3EB05E.C564D84A@zhengmai.com.cn>
References: <3A3EB05E.C564D84A@zhengmai.com.cn>

"He Weiping(Laser Henry)" <laser@zhengmai.com.cn> writes:
> laser_zh=# select round(42.5);
>  round
> -------
>     42
> (1 row)
>
> is it correct? I think result should be 43.

It's correct, if the underlying float arithmetic is IEEE-compliant.
Rounding for exact half-integral values is supposed to be "round to
nearest even".  So 42.5 goes to 42, but 43.5 goes to 44.

I notice our NUMERIC rounding code does not do that ... perhaps it
should.

Also, the numeric round() function is just plain broken:

regression=# select round(42.5::numeric);
ERROR:  Function 'numeric_round(numeric, int4)' does not exist
        Unable to identify a function that satisfies the given argument types
        You may need to add explicit typecasts
regression=# select round(42.5::numeric,0);
 round
-------
    43
(1 row)

Looks like a silly oversight in the pg_proc entry for round(numeric).

			regards, tom lane



view thread (4+ messages)  latest in thread

Message-ID: <2639.977187769@sss.pgh.pa.us>
Permalink:  ../2639.977187769@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2639.977187769@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, laser@zhengmai.com.cn
  Subject: Re: some errors and/or bugs?
  In-Reply-To: <2639.977187769@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox