Search Postgresql Archives

Re: integer instead of 'double precision'?

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

 



On Mon, Nov 12, 2012 at 02:16:21PM +0100, Willy-Bas Loos wrote:
> On Fri, Sep 9, 2011 at 5:09 PM, Guillaume Lelarge <guillaume@xxxxxxxxxxxx>wrote:
> 
> > You divide an integer with an integer, that should give you an integer.
> >
> 
> Can you tell me the reasoning behind that idea?
> Is it a rule that the output type of an operator must equal the input type?
> In this case that doesn't seem locigal. I think that the "/" operator
> should return something that allows fractions, since the operator creates
> fractions so frequently.

The thing is, you often do need the version that truncates. It's
supported by the underlying system and if you want a float as output
you can cast one of the arguments to float to do that.  It's been like
this forever (C does it too for example).

For integers it may help if you think of it in combination with the
modulus operator (%).

Python 3 recently changed to give float output by default, but also
provides a // operator to access the truncated version.

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog@xxxxxxxxx>   http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.
   -- Arthur Schopenhauer

Attachment: signature.asc
Description: Digital signature


[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