Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Alban Hertroys [mailto:haramrae@xxxxxxxxx] 
> Sent: Wednesday, 12 October 2011 1:35 AM
> To: Tom Lane
> Cc: Harvey, Allan AC; pgsql-general@xxxxxxxxxxxxxx
> Subject: Re:  Should casting to integer produce same 
> result as trunc()
> 
> On 11 October 2011 15:41, Tom Lane <tgl@xxxxxxxxxxxxx> wrote:
> > Alban Hertroys <haramrae@xxxxxxxxx> 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@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux