Re: About PostgreSQL's limit on arithmetic operations

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Shridhar Daithankar <shridhar(at)frodo(dot)hserus(dot)net>
Cc: Devrim GUNDUZ <devrim(at)gunduz(dot)org>, PostgreSQL Mailing Lists-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: About PostgreSQL's limit on arithmetic operations
Date: 2004-09-29 11:43:11
Message-ID: 20040929114311.GC5152@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Sep 29, 2004 at 04:51:30PM +0530, Shridhar Daithankar wrote:
> Probably because the normal integer is 4 bytes long and bigint is 8 bytes
> long. The value above is exactly 2^63 at which a 8 bytes long signed bigint
> should flip sign/overflow. I am still puzzled with correct value and negative
> sign..

Because in signed integer arithmatic the negative numbers go one
further than the positive numbers. So the largest positive number is
2^63-1 and the largest negative number is -2^63.

Or put it another way: -2^63 = +2^63. It's the far end of the loop,
exactly opposite the zero.

> For arbitrary precision integer, you have to use numeric. It is not same as
> oracle.

I would say that it should produce an overflow error rather than just
returning the wrong answer, but that's not my call...

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2004-09-29 12:19:08 Re: Multiple Rules :: Postgres Is confused !!
Previous Message Najib Abi Fadel 2004-09-29 11:40:19 Re: Multiple Rules :: Postgres Is confused !!