Re: BUG #3289: SIN(PI()) expected to return 0, but returns garbage

Lists: pgsql-bugs
From: "Daniel Kastenholz" <mail(at)danielkastenholz(dot)de>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #3289: SIN(PI()) expected to return 0, but returns garbage
Date: 2007-05-17 09:48:35
Message-ID: 200705170948.l4H9mZRI040983@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 3289
Logged by: Daniel Kastenholz
Email address: mail(at)danielkastenholz(dot)de
PostgreSQL version: 8.1, 8.2.4
Operating system: Linux, Windows
Description: SIN(PI()) expected to return 0, but returns garbage
Details:

Trouble case:

Action:
Type in SELECT SIN(PI())

Expected output:
0

Actual output:
* Windows, using 8.2.4:
garbage (-2.2......)

* Linux, using 8.1:
garbage (1.22.......)

--

Comments:
SIN(3.1414) and SIN(3.1417) come close to 0 and work on both platforms.
SIN(3.1415) and SIN(3.1416) produce the same garbage output as using PI() on
both platforms.


From: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
To: Daniel Kastenholz <mail(at)danielkastenholz(dot)de>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3289: SIN(PI()) expected to return 0, but returns garbage
Date: 2007-05-17 10:38:02
Message-ID: 464C308A.7010103@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Daniel Kastenholz wrote:
> Type in SELECT SIN(PI())
>
> Expected output:
> 0
>
> Actual output:
> * Windows, using 8.2.4:
> garbage (-2.2......)
>
> * Linux, using 8.1:
> garbage (1.22.......)
>
> --
>
> Comments:
> SIN(3.1414) and SIN(3.1417) come close to 0 and work on both platforms.
> SIN(3.1415) and SIN(3.1416) produce the same garbage output as using PI() on
> both platforms.

You don't get 0 because the value of pi is just an approximation, and
most likely the output of sin is not exact either. What you get is
pretty darn close to 0, however. Apparently you didn't read the output
carefully: it's in scientific notation. I'm getting

1.22460635382238e-16

on my laptop, which means 1.22460635382238 * 10^(-16).

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com