agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Max Lipsky <maxlipsky@gmail.com>
To: pgsql-sql@lists.postgresql.org
Subject: Problem in
Date: Thu, 25 Apr 2019 16:45:18 +0300
Message-ID: <2164C531-EAA3-4CAF-996F-FEB0E5F73B32@gmail.com> (raw)
Hi everyone!
I found an incomprehensible behavior of some functions in PostgreSQL 9.5.12 (for 10.6 working good).
For example:
SELECT acos(
cos(radians(48.9193))
* cos(radians(48.9193))
* cos(radians(2.5431) - radians(2.5431))
+ sin(radians(48.9193))
* sin(radians(48.9193))
) as result;
This returned [22003] ERROR: input is out of range
But this one working good:
SELECT acos(
cos(radians(48.9192))
* cos(radians(48.9192))
* cos(radians(2.5431) - radians(2.5431))
+ sin(radians(48.9192))
* sin(radians(48.9192))
) as result;
The difference is 48.9193 => 48.9192
I did research a bit and found what this query
SELECT cos(0.8538028527708621) * cos(0.8538028527708621) + sin(0.8538028527708621) * sin(0.8538028527708621) as s1;
Returned 1.0000000000000002
SELECT cos(0.8538028527708621) * cos(0.8538028527708621) as s1; -- 0.43180849723816966
SELECT sin(0.8538028527708621) * sin(0.8538028527708621) as s1; -- 0.5681915027618305
Looks like cos() have scale = 17 (sometimes), but sin() have scale 16
P.S. I saw it only in the IntelliJ IDEA console. In the native console these values will be rounded:
SELECT cos(0.8538028527708621) * cos(0.8538028527708621) as s1;
s1
------------------
0.43180849723817
* * *
Best Regards,
Max Lipsky
view thread (9+ messages) latest in thread
Message-ID: <2164C531-EAA3-4CAF-996F-FEB0E5F73B32@gmail.com>
Permalink: ../2164C531-EAA3-4CAF-996F-FEB0E5F73B32@gmail.com/
Also on: postgresql.org/message-id/2164C531-EAA3-4CAF-996F-FEB0E5F73B32@gmail.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: maxlipsky@gmail.com, pgsql-sql@lists.postgresql.org
Subject: Re: Problem in
In-Reply-To: <2164C531-EAA3-4CAF-996F-FEB0E5F73B32@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox