Re: BUG #3791: Bug in aritmethic calculations

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Michailas" <michailas(dot)p(at)gmail(dot)com>
Cc: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #3791: Bug in aritmethic calculations
Date: 2007-11-30 10:11:57
Message-ID: 873auocaaa.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Michailas" <michailas(dot)p(at)gmail(dot)com> writes:

> postgres=# SELECT abs(300 - 200)/200*100 as bad, abs(300-200)*100/200 as
> good;
>
> bad | good
> -----+------
> 0 | 50
> (1 row)

That's how integer arithmetic works. Try just 1/2 and you'll see you get 0.
But if you do floating point arithmetic with 1.0/2 you'll get 0.5.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's RemoteDBA services!

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Gregory Stark 2007-11-30 10:13:53 Re: BUG #3790: pg_restore error canceling statement due to user request
Previous Message Gevik Babakhani 2007-11-30 10:00:16 Re: BUG #3791: Bug in aritmethic calculations