> -----Original Message-----
> From: Alban Hertroys [mailto:haram...@gmail.com] 
> Sent: Wednesday, 12 October 2011 1:35 AM
> To: Tom Lane
> Cc: Harvey, Allan AC; pgsql-general@postgresql.org
> Subject: Re: [GENERAL] Should casting to integer produce same 
> result as trunc()
> 
> On 11 October 2011 15:41, Tom Lane <t...@sss.pgh.pa.us> wrote:
> > Alban Hertroys <haram...@gmail.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)
> 
> I figured it would be something like that. Is that how it's defined in
> the SQL standard?
> 
> All other programming languages I've come to know truncate floats on
> such casts (C, php, python, java, to name a few).
> This is probably quite surprising to people used to these languages.

Thanks guys, yes C/C++ is my poison, forming my expectations.

Allan


The material contained in this email may be confidential, privileged or 
copyrighted. If you are not the intended recipient, use, disclosure or copying 
of this information is prohibited. If you have received this document in error, 
please advise the sender and delete the document. Neither OneSteel nor the 
sender accept responsibility for any viruses contained in this email or any 
attachments.

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to