Re: [Fwd: Re: ruleutils with pretty-print option]

From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: [Fwd: Re: ruleutils with pretty-print option]
Date: 2003-07-31 16:05:27
Message-ID: 3F293E47.4060207@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Tom Lane wrote:

>Andreas Pflug <pgadmin(at)pse-consulting(dot)de> writes:
>
>
>>Well, to me it's not well-known that floating-point addition is not
>>associative, do I need to re-learn my math?
>>
>>
>
>regression=# select (1.0::float8 + (-1.0::float8)) + 1.0e-20::float8;
> ?column?
>----------
> 1e-20
>(1 row)
>
>regression=# select 1.0::float8 + ((-1.0::float8) + 1.0e-20::float8);
> ?column?
>----------
> 0
>(1 row)
>
>
>

Hi Tom,

I already suspected an example like this. Obviously in a pure math
world, the second example is wrong, caused by implicite rounding.
Fortunately, if omitting the float8 casts numeric is used, delivering
ultimate precision.

Just for curiousity: on MSSQL2000, the first will deliver
9.99999999999995E-21, and if the type decimal(30,25) is used both give
0.00000000000. Even better, CAST( CAST(1E-20 AS DECIMAL(30,25) AS
FLOAT) is 0.0 :->

Oracle 9.2 will calculate correctly with float down to 1.0e-40.

Regards,
Andreas

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Josh Berkus 2003-07-31 16:43:32 Re: Proof-of-concept for initdb-time shared_buffers selection
Previous Message Manfred Koizar 2003-07-31 16:01:21 Re: [Fwd: Re: ruleutils with pretty-print option]