BUG #4514: Pi division error

Started by Traci Sumpterover 17 years ago3 messagesbugs
Jump to latest
#1Traci Sumpter
traci.sumpter@opus.com.au

The following bug has been logged online:

Bug reference: 4514
Logged by: Traci Sumpter
Email address: traci.sumpter@opus.com.au
PostgreSQL version: 8.3.3
Operating system: Linux
Description: Pi division error
Details:

I am trying to do some calculations within Postgresql and am not getting the
expected result. the first set proves that the pi works as expected with
multiplication.

Equation 180*pi
VB 565.486677646163
Calculator 565.486677646163
PostgreSQL 565.486677646163
Php 565.48667764616

However if I extend this equation postgres definately fails this test.

Equation (315-0)/180*pi
VB 5.49778714378213
Calculator 5.497787144
PostgreSQL 3.14159265358979
Php 5.4977871437821

Help

#2Rodriguez Fernando
rodriguez@ort.edu.uy
In reply to: Traci Sumpter (#1)
Re: BUG #4514: Pi division error

Traci Sumpter escribió:

The following bug has been logged online:

Bug reference: 4514
Logged by: Traci Sumpter
Email address: traci.sumpter@opus.com.au
PostgreSQL version: 8.3.3
Operating system: Linux
Description: Pi division error
Details:

I am trying to do some calculations within Postgresql and am not getting the
expected result. the first set proves that the pi works as expected with
multiplication.

Equation 180*pi
VB 565.486677646163
Calculator 565.486677646163
PostgreSQL 565.486677646163
Php 565.48667764616

However if I extend this equation postgres definately fails this test.

Equation (315-0)/180*pi
VB 5.49778714378213
Calculator 5.497787144
PostgreSQL 3.14159265358979
Php 5.4977871437821

Help

hola el problema que entero/entero = entero
lo que debes hacer es

(315.0-0)/180*pi

saludos Fernando

#3Tomasz Ostrowski
tometzky@batory.org.pl
In reply to: Traci Sumpter (#1)
Re: BUG #4514: Pi division error

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