From: | Erik Brandsberg <erik(at)heimdalldata(dot)com> |
---|---|
To: | szy <598546998(at)qq(dot)com> |
Cc: | pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Inconsistent results for division and multiplication operations |
Date: | 2024-11-25 15:53:38 |
Message-ID: | CAFcck8EQ3h15-P=Ndt269gE50FDMc=BmWM0iVfUuLbev5HJUbQ@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
This is a common issue with using floating point math. You will see the
same issue with many systems. Basically, the order of operations can
trigger very minor differences in results, but if you round the first
result to the same number of significant digits as the input, it would be
identical.
https://learn.microsoft.com/en-us/office/troubleshoot/access/floating-calculations-info
On Mon, Nov 25, 2024 at 10:46 AM szy <598546998(at)qq(dot)com> wrote:
>
> Hi PostgreSQL community,
>
> I have observed inconsistent results when performing division and
> multiplication operations in PostgreSQL.
>
> postgres=# select 1.003/1.002*5.01;
> ?column?
> --------------------------
> 5.0149999999999999999806
> (1 row)
>
> postgres=# select 1.003*5.01/1.002;
> ?column?
> --------------------
> 5.0150000000000000
> (1 row)
>
> However, the expected result should be consistent for both queries. The
> actual results differ
>
>
> ------------------------------
> szy
> 598546998(at)qq(dot)com
>
> <https://wx.mail.qq.com/home/index?t=readmail_businesscard_midpage&nocheck=true&name=szy&icon=http%3A%2F%2Fthirdqq.qlogo.cn%2Fg%3Fb%3Doidb%26k%3DiaAmEopniaNALwVq2rar6n3Q%26kti%3DZLTe1AAAAAE%26s%3D640%26t%3D1622504424&mail=598546998%40qq.com&code=Gezi7Gl9e-YYAktdETJ0hu2-JIM5l3FTObsX105iXnV2Az4OVWt5ENk8nrBlqhIKcNOvXiaTQhfswEOxGaCYhQ>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | szy | 2024-11-25 16:12:15 | 回复: Inconsistent results for division and multiplication operations |
Previous Message | szy | 2024-11-25 15:46:28 | Inconsistent results for division and multiplication operations |