Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aMnBr-00036K-KI for pgsql-hackers@arkaria.postgresql.org; Sat, 23 Jan 2016 01:40:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aMnBr-0002Z2-2z for pgsql-hackers@arkaria.postgresql.org; Sat, 23 Jan 2016 01:40:35 +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_SHA384:256) (Exim 4.84) (envelope-from ) id 1aMnBp-0002YH-Qr for pgsql-hackers@postgresql.org; Sat, 23 Jan 2016 01:40:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aMnBm-0003Mf-G6 for pgsql-hackers@postgresql.org; Sat, 23 Jan 2016 01:40:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u0N1eNvX021073; Fri, 22 Jan 2016 20:40:23 -0500 From: Tom Lane To: Dean Rasheed cc: Michael Paquier , Peter Eisentraut , PostgreSQL Hackers Subject: Re: Proposal: Trigonometric functions in degrees In-reply-to: <11878.1453495831@sss.pgh.pa.us> References: <562E82F7.2060704@gmx.net> <1671.1445890789@sss.pgh.pa.us> <5178.1445899865@sss.pgh.pa.us> <31706.1448892680@sss.pgh.pa.us> <11878.1453495831@sss.pgh! .pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 22 Jan 2016 15:50:31 -0500" Date: Fri, 22 Jan 2016 20:40:23 -0500 Message-ID: <21072.1453513223@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org I wrote: > Dean Rasheed writes: >> Attached are patches for this and the new functions in degrees, now >> with POSIX compatible Inf/NaN handling. > Pushed with minor, mostly cosmetic fixes. So the early returns from the buildfarm aren't very good: * tern/sungazer isn't getting exactly 0.5 from sind(30). * narwhal isn't getting exactly 1 from tand(45) or cotd(45). It also is producing "0" not "-0" from tand(180) and cotd(270). * gaur likewise is getting "0" not "-0" from tand(180) and cotd(270). The tern/sungazer result implies that this: return (sin(x * (M_PI / 180.0)) / sin(30.0 * (M_PI / 180.0))) / 2.0; is not producing exactly 0.5, which means that the two sin() calls aren't producing identical results, which I suspect is best explained by the theory that the compiler is rearranging 30.0 * (M_PI / 180.0) into (30.0 * M_PI) / 180.0, and getting a slightly different number that way. I think we could fix that by replacing (M_PI / 180.0) by a hard-wired constant (computed to say 20 digits or so). I'd be inclined to do that throughout the file for consistency; however, in principle such a change might affect existing results from the radians() and degrees() functions. The tand(45) problem doesn't seem especially surprising, because we're really not making any effort to ensure that that result is exact. A brute-force way to fix it would be to divide (sind_q1(arg1) / cosd_q1(arg1)) by (sind_q1(45.0) / cosd_q1(45.0)) but that seems rather expensive, and possibly subject to the compiler deciding to reorder the arithmetic operations. I wonder if there's a smarter way. As for the minus-zero issues, I doubt that (a) there is a basis for claiming that minus-zero is more correct than plain zero, or (b) the user community for this feature really wants minus-zero results anyhow. I propose getting rid of minus-zero outputs from tand and cotd by dint of code like if (result == 0.0) result = 0.0; Thoughts? regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers