Re: BUG in postgres mathematic - Mailing list pgsql-bugs

From Robert B. Easter
Subject Re: BUG in postgres mathematic
Date
Msg-id 0101250729000J.08820@comptechnews
Whole thread Raw
In response to BUG in postgres mathematic  (Max Vaschenko <max@nino.ru>)
Responses Re: BUG in postgres mathematic
List 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@comptechnews.com ---------
-- CompTechNews Message Board http://www.comptechnews.com/ --
-- CompTechServ Tech Services http://www.comptechserv.com/ --
---------- http://www.comptechnews.com/~reaster/ ------------

pgsql-bugs by date:

Previous
From: pgsql-bugs@postgresql.org
Date:
Subject: large objects overwriting bug
Next
From: Peter T Mount
Date:
Subject: Re: Re: [INTERFACES] jdbc driver: Support for 'BOOL'