Re: BUG in postgres mathematic

From: "Robert B(dot) Easter" <reaster(at)comptechnews(dot)com>
To: Max Vaschenko <max(at)nino(dot)ru>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG in postgres mathematic
Date: 2001-01-25 12:29:00
Message-ID: 0101250729000J.08820@comptechnews
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

This problem is not specific to Postgres. If you play around with a little C
program like:

#include <stdio.h>

int main(int argc, char * argv[])
{
float f = 27.81;
int i = 5;
int l = 100;

int ii = i*f*l;
long ll = l*f*i;
float ff = i*f*l;

printf("%i\n", ii);
printf("%li\n", ll);
printf("%.5f\n", ff);
printf("%i\n", (int) ff);
}

It prints:

13904
13904
13905.00000
13905

There is probably a good explanation for this. gcc 2.95 and egcs 2.91.66 do
this. Maybe a rounding problem.

On Thursday 25 January 2001 05:34, Max Vaschenko wrote:
> Postgres-7.0.3-2
> RedHat-6.2
>
> SELECT int8(5*27.81*100);
> 13904
>
> SELECT int4(5*27.81*100);
> 13905
>
> SELECT int8(27.81*100*5);
> 13905

--
-------- Robert B. Easter reaster(at)comptechnews(dot)com ---------
-- CompTechNews Message Board http://www.comptechnews.com/ --
-- CompTechServ Tech Services http://www.comptechserv.com/ --
---------- http://www.comptechnews.com/~reaster/ ------------

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter T Mount 2001-01-25 13:26:50 Re: Re: [INTERFACES] jdbc driver: Support for 'BOOL'
Previous Message pgsql-bugs 2001-01-25 11:54:20 large objects overwriting bug