Re: BUG #4514: Pi division error - Mailing list pgsql-bugs

From Tomasz Ostrowski
Subject Re: BUG #4514: Pi division error
Date
Msg-id 4912FFD8.7030208@batory.org.pl
Whole thread Raw
In response to BUG #4514: Pi division error  ("Traci Sumpter" <traci.sumpter@opus.com.au>)
List 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

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #4515: UPDATE strange behavior
Next
From: "Alex Hunsaker"
Date:
Subject: Re: plperl & sort