Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hKKiG-0005ZA-N9 for pgsql-sql@arkaria.postgresql.org; Sat, 27 Apr 2019 10:37:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hKKiD-0005eg-1P for pgsql-sql@arkaria.postgresql.org; Sat, 27 Apr 2019 10:37:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hKHpK-0005fS-1u for pgsql-sql@lists.postgresql.org; Sat, 27 Apr 2019 07:32:50 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hKHpD-0007ZM-1Q for pgsql-sql@lists.postgresql.org; Sat, 27 Apr 2019 07:32:49 +0000 Received: by mail-lf1-x142.google.com with SMTP id o16so4133523lfl.7 for ; Sat, 27 Apr 2019 00:32:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=f2UhVaElIwazg40SrmmTEFGjr4Dfm+KGsz7BzCEG2gE=; b=PqFqijSZbyHq7FSuLpjHgIrojIvnjCF6fJItyzNJP8sdsMJHT/mMLN+d1CFXwO4hES EP6PpJChJxlY2pPvDCo0QzsucX/oJTUx+lHZ1/Rf4J9clulmLfhCixFqgBBxiAwHjemR jJLMv7RNYVrfXzk5V5+yeh6JNKWMnQ61O19O7uu2knF0ovu2Xu55S2N9MY2DQVVYB1sc uYnTNgZwzciNs1YRZbMrA42iwxwMSvMxuscHK83ZNM0+35mioqv+mwejQi74ZfM4T1Qr aZebLsW9036fBDHqgtAKdROeFlu5g6JrCSsIDa98czLkkpYlnaELI03T0HtyXzRUdYxO tbAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=f2UhVaElIwazg40SrmmTEFGjr4Dfm+KGsz7BzCEG2gE=; b=ah/jCElMBuXG3/SsqY4KHHrVgmgzgU/WYG3rX6R6wo6HbqrAu30pisoSg4DGEUkHei WGNIA/qCJT5Bn7cVwkXEa3KEdRT6IsR8JPbcsD0O7SXT2CoyxtrQOZlYSYJprhQSmcDJ 9RmupSH+7uhBXJ8/Jve67o52nK2R1WQ8VAn1Nn8RkaINsPyx7/Lr1WpnNldikaZykIMV mapadGxWVJeUyEZKtH+w3eBn6J1Z9dZfrO1SNbWZjafu7gnaZfUZ+4bCHNM+8oUXsT7X YyOj998cHn+3lXhJpHcr7W0w9qahEDqmFPNSI/4KWSqAkClfHNqvUGtD5vCaRv1jw+5y ZIDw== X-Gm-Message-State: APjAAAVWd6ofe8tLr+dBTo4k/rolm7Wn+6yOx6lMEsgOqlFAzJ0jLZZJ pS86+eF1rFmhEr6NmsYQdzQ= X-Google-Smtp-Source: APXvYqwqbjmdqoD6ahsZl1cl0KyC4/FBAwm/oGHS2hO+3sYoG0+gGyqt8I5GiGvqPNtgzXnbhX4vBg== X-Received: by 2002:a19:4c88:: with SMTP id z130mr23245016lfa.29.1556350361231; Sat, 27 Apr 2019 00:32:41 -0700 (PDT) Received: from [10.8.2.2] ([165.231.142.14]) by smtp.gmail.com with ESMTPSA id s21sm7420093lfb.0.2019.04.27.00.32.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Apr 2019 00:32:40 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Subject: Re: Problem in From: Max Lipsky In-Reply-To: Date: Sat, 27 Apr 2019 10:32:37 +0300 Cc: Tom Lane , pgsql-sql@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <2164C531-EAA3-4CAF-996F-FEB0E5F73B32@gmail.com> <26108.1556211406@sss.pgh.pa.us> <32A34C31-946E-4946-8CD1-DB36F70160ED@gmail.com> To: Andrej X-Mailer: Apple Mail (2.3445.104.8) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello Andrej That=E2=80=99s true, it's depends of system (CPU and x87 instructions) But for some reason I thought that the calculations should be = symmetrical, but this is not :) I made small program on c, which calculating sin, cos and (sin^2 + = cos^2) 1. sin & cos (0.8538028527708625) > = 0.753784785440665960898343200824 0.657121371770975959414329281572 2. sin & cos (0.8538028527708626) > = 0.753784785440666071920645663340 0.657121371770975848392026819056 3. sin & cos (0.8538028527708627) > = 0.753784785440666071920645663340 0.657121371770975848392026819056 4. sin & cos (0.8538028527708628) > = 0.753784785440666071920645663340 0.657121371770975737369724356540 5. sin & cos (0.8538028527708629) > = 0.753784785440666182942948125856 0.657121371770975737369724356540 6. sin & cos (0.8538028527708630) > = 0.753784785440666293965250588371 0.657121371770975626347421894025 2, 3, 4 =E2=80=94 same result for SIN 2, 3 and 4,5 =E2=80=94 same result for COS 1. sin^2 + cos^2 (0.8538028527708625) > = 1.000000000000000000000000000000 2. sin^2 + cos^2 (0.8538028527708626) > = 1.000000000000000000000000000000 3. sin^2 + cos^2 (0.8538028527708627) > = 1.000000000000000000000000000000 4. sin^2 + cos^2 (0.8538028527708628) > = 0.999999999999999888977697537484 5. sin^2 + cos^2 (0.8538028527708629) > = 1.000000000000000000000000000000 6. sin^2 + cos^2 (0.8538028527708630) > = 1.000000000000000000000000000000 Also, if you change sin to (1 - cos^2) in sql query =E2=80=94 it will be = works good. Error comes from FSIN/FCOS instruction, but as Tom said =E2=80=94 it=E2=80= =99s OK (within acceptable limits). It was just a little unexpected for me :) P.S. OK for HTML > On 27 Apr 2019, at 03:34, Andrej wrote: >=20 > Max, just try >=20 > SELECT 1 - ( 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; >=20 > You may find that enlightening. I did play with this for a while > yesterday (and asked people on IRC), and it seems to heavily depend > the on local systems set-up. > Seems that e.g. MacOS mojave & postgres9.6 from brew work as you > expect; someone confirmed postgres on Suse to do the right thing. > 9.6.15 on Ubuntu 16.04 > gives a remainder that would then make the acos fail ... >=20 > On Fri, 26 Apr 2019 at 19:24, Max Lipsky wrote: >>=20 >> Hello Tom! >>=20 >> I think is too much for roundoff error >>=20 >> Found funny post about it: >> = https://randomascii.wordpress.com/2014/10/09/intel-underestimates-error-bo= unds-by-1-3-quintillion/ >> http://notabs.org/fpuaccuracy/index.htm >>=20 >>=20 >>=20 >> On 25 Apr 2019, at 19:56, Tom Lane wrote: >>=20 >> Max Lipsky writes: >>=20 >> 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; >>=20 >>=20 >> This returned [22003] ERROR: input is out of range >>=20 >>=20 >> Not too surprising, because (at least on my machine) >>=20 >> regression=3D# select cos(radians(48.9193)) >> regression-# * cos(radians(48.9193)) + = sin(radians(48.9193)) >> regression-# * sin(radians(48.9193)); >> ?column? >> -------------------- >> 1.0000000000000002 >> (1 row) >>=20 >> Problems of this sort are inevitable when working with = finite-precision >> math. >>=20 >> https://en.wikipedia.org/wiki/Round-off_error >>=20 >> regards, tom lane >>=20 >>=20 >=20 >=20 > --=20 > Please don't top post, and don't use HTML e-Mail :} Make your quotes = concise. >=20 > http://www.georgedillon.com/web/html_email_is_evil.shtml > http://www.catb.org/jargon/html/email-style.html