Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aN4dB-0008Lm-UE for pgsql-hackers@arkaria.postgresql.org; Sat, 23 Jan 2016 20:17:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aN4dB-0004Kw-GP for pgsql-hackers@arkaria.postgresql.org; Sat, 23 Jan 2016 20:17:57 +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 1aN4bq-0002s0-TC for pgsql-hackers@postgresql.org; Sat, 23 Jan 2016 20:16:35 +0000 Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aN4bn-0000Xy-5b for pgsql-hackers@postgresql.org; Sat, 23 Jan 2016 20:16:34 +0000 Received: by mail-pa0-x22e.google.com with SMTP id yy13so59142213pab.3 for ; Sat, 23 Jan 2016 12:16:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=EJBG6JvDrJKex1hs7SqHh5l405hnlMAs6IMgoK00Szw=; b=ASLmPrxquQOMkYYzf12zbR+CJme2mrsA4tOhjXmF9i3tpCxxj0z5VgR7X3C+UV4XIU Q56rHq0WLiQtbDeCN+LvSaQa4bxtZliYLBJ0BStG27fjZfJT4A2oofhOMpRgwa3Krglj r4yg6lWOaPmm5u0iwFQ6vezOvlvlJ7UDHzLZk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=EJBG6JvDrJKex1hs7SqHh5l405hnlMAs6IMgoK00Szw=; b=WJ/gwuopcJSfc9BZIRbg/rp6kzAekG63GQZvrlAMxunepg+npC6FniCFsvd/t28vKA Yenp4eLNTN3WkNJVAtVGLLG6iLI21FzoeskrMZ/jN+DJDDvHd6OL5cDSdjZThVSP+bGZ 1aAUS9VRUFRR63jax6kJ4XJ4dZI0hVlDBdO8TwcEQE+rylowifxqKRzmK9UJoVCkcgFM mGEKc19lBwWowRs8trn6pWcUadXv2aThBXnq2kkTmebdETW6aJ7xxTbPyqPOFkhBdI1e rXaRvRQrbK9Hy/aQYovZnDOiawmOdZuFbjDQxbPYh5nSlQGBTyKIOTBZD8owTK4T/pFp yq0w== X-Gm-Message-State: AG10YOTNeQPjQU+cWKNN4V9zOTUlYwdNAnrrAKEtevEEzKKMfC54KeCcI2nwt6pJNKcrfg== X-Received: by 10.66.180.48 with SMTP id dl16mr14139228pac.39.1453580188145; Sat, 23 Jan 2016 12:16:28 -0800 (PST) Received: from tornado.leadboat.com (c-98-248-47-228.hsd1.ca.comcast.net. [98.248.47.228]) by smtp.gmail.com with ESMTPSA id q136sm18139023pfq.66.2016.01.23.12.16.26 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 23 Jan 2016 12:16:27 -0800 (PST) Date: Sat, 23 Jan 2016 15:16:25 -0500 From: Noah Misch To: Tom Lane Cc: Dean Rasheed , Michael Paquier , Peter Eisentraut , PostgreSQL Hackers Subject: Re: Proposal: Trigonometric functions in degrees Message-ID: <20160123201625.GA3691823@tornado.leadboat.com> References: <31706.1448892680@sss.pgh.pa.us> <21072.1453513223@sss.pgh.pa.us> <28880.1453568920@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <28880.1453568920@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) X-Pg-Spam-Score: -2.7 (--) 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 On Sat, Jan 23, 2016 at 12:08:40PM -0500, Tom Lane wrote: > I wrote: > > So the early returns from the buildfarm aren't very good: > > * tern/sungazer isn't getting exactly 0.5 from sind(30). > > > 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). > > So I pushed that, and tern/sungazer are still failing. Noah, could you > trace through that and see exactly where it's going off the rails? The second sin() is a constant, so gcc computes it immediately but sends the first sin() to libm. The libm sin() is slightly more accurate. In %a notation, AIX libm computes sin(30.0 * RADIANS_PER_DEGREE) as 0x1p-1 while gcc computes it as 0x1.fffffffffffffp-2, a difference of one ULP. (Both "30.0 * RADIANS_PER_DEGREE" and "30.0 * (M_PI / 180.0)" match the runtime computation of 0x1.0c152382d7365p-1.) To reliably produce exact answers, this code must delay all trigonometric calculations to runtime. On sungazer, the float8 test happens to pass if I rebuild float.c with -fno-builtin-sin; that leaves calls like acos(0.5) and cos(60.0 * RADIANS_PER_DEGREE) unprotected, though. -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers