Re: Should casting to integer produce same result as trunc()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alban Hertroys <haramrae(at)gmail(dot)com>
Cc: "Harvey, Allan AC" <HarveyA(at)OneSteel(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Should casting to integer produce same result as trunc()
Date: 2011-10-11 13:41:45
Message-ID: 25886.1318340505@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alban Hertroys <haramrae(at)gmail(dot)com> writes:
> On 11 Oct 2011, at 2:55, Harvey, Allan AC wrote:
>> My simple understanding of trunc() and casting to an integer says that
>> there is a bug here.

> Which the type-cast should round to 4380103 and 4380104 respectively.
> It doesn't:

That's because a cast from float to int rounds, it doesn't truncate.

regression=# select (4.7::float8)::int;
int4
------
5
(1 row)

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Eric Radman 2011-10-11 14:06:50 Global Variables?
Previous Message Krishnanand Gopinathan Sathikumari 2011-10-11 12:33:38 Question on GiST re-index