Re: numeric and float converts to int differently? - Mailing list pgsql-sql

From Tom Lane
Subject Re: numeric and float converts to int differently?
Date
Msg-id 23857.1067358382@sss.pgh.pa.us
Whole thread Raw
In response to numeric and float converts to int differently?  ("SZŰCS Gábor" <surrano@mailbox.hu>)
List pgsql-sql
"SZŰCS Gábor" <surrano@mailbox.hu> writes:
> QUESTION 1: Is it intentional that converting 0.5 to int4
> - from numeric: rounds *away from* zero
> - from float: rounds *towards* zero (tried float4 and float8 too)?

Numeric currently rounds away from zero.  We cannot guarantee to make
it work the same as float, because float's rounding behavior is
platform-dependent.  A common but not universal behavior is "round to
nearest even integer".  See the recent thread about the round() function
(I forget which list it was in, but it was within the past week).

> QUESTION 2: Is it safe to assume it won't change (haven't changed) in the
> upcoming versions?

Numeric's behavior hasn't changed as of 7.4beta5.  I do not have a
crystal ball to predict whether we might change it in the future.
I doubt we will ever try to override the platform behavior for float.
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: bug in working with TEXT constants ?
Next
From: "SZŰCS Gábor"
Date:
Subject: Re: numeric and float converts to int differently?