Skip site navigation (1) Skip section navigation (2)

Re: BUG #4514: Pi division error

From: Tomasz Ostrowski <tometzky(at)batory(dot)org(dot)pl>
To: Traci Sumpter <traci(dot)sumpter(at)opus(dot)com(dot)au>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4514: Pi division error
Date: 2008-11-06 14:31:52
Message-ID: 4912FFD8.7030208@batory.org.pl (view raw or flat)
Thread:
Lists: pgsql-bugs
On 2008-11-06 07:56, Traci Sumpter wrote:

> Equation   (315-0)/180*pi
> PostgreSQL 3.14159265358979

You equation in SQL looks like this:

=> select (315-0)/180*pi from (select 3.14159265358979 as pi) as a;

Which is an equivalent of:

=> select (315/180)*pi from (select 3.14159265358979 as pi) as a;

And because 315 and 180 are integers so (315/180) is rounded down to
integer (1):

=> select 1*pi from (select 3.14159265358979 as pi) as a;

I think you need:

=> select (315.0-0)/180*pi from (select 3.14159265358979 as pi) as a;
5.497787143782132500000000000000

Any strongly typed language will do this, for example in python:

$ python -c 'pi=3.14159265358979; print (315-0)/180*pi;'
3.14159265359
$ python -c 'pi=3.14159265358979; print (315.0-0)/180*pi;'
5.49778714378

Regards
Tometzky
-- 
...although Eating Honey was a very good thing to do, there was a
moment just before you began to eat it which was better than when you
were...
                                                      Winnie the Pooh

In response to

pgsql-bugs by date

Next:From: Alex HunsakerDate: 2008-11-06 15:37:58
Subject: Re: plperl & sort
Previous:From: Tom LaneDate: 2008-11-06 14:13:58
Subject: Re: BUG #4515: UPDATE strange behavior

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group