Re: Float/Double cast to int

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Feng Tian <ftian(at)vitessedata(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Float/Double cast to int
Date: 2015-05-21 19:01:25
Message-ID: 32603.1432234885@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Feng Tian <ftian(at)vitessedata(dot)com> writes:
> Here is a query, server was built witch GCC on Linux, AMD64.

> ftian=# select 1.5::int, 1.5::double precision::int, 314.5::int,
> 314.5::double precision::int;
> int4 | int4 | int4 | int4
> ------+------+------+------
> 2 | 2 | 315 | 314
> (1 row)

> I believe this is because rint is broken -- can some expert on IEEE754
> please help confirm that this is a bug?

rint() is doing what the IEEE spec says, ie round to nearest even.
Your third expression is doing numeric-to-int, and that code doesn't
obey the IEEE spec. We've had discussions (not too long ago) about
making these behaviors more consistent, but people seem to be too
afraid of backwards-compatibility problems if we change it.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-05-21 19:17:50 Re: GROUPING
Previous Message Simon Riggs 2015-05-21 18:55:38 Re: INSERT ... ON CONFLICT DO UPDATE with _any_ constraint