pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Peter Eisentraut <peter_e@gmx.net>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Proposal: Trigonometric functions in degrees
Date: Fri, 22 Jan 2016 20:40:23 -0500
Message-ID: <21072.1453513223@sss.pgh.pa.us> (raw)
In-Reply-To: <11878.1453495831@sss.pgh.pa.us>
References: <CAEZATCXxdzxb2Mvi0-Xvp43tfvw-bUi703HdAJuLUd7dt5-ZgQ@mail.gmail.com>
	<562E82F7.2060704@gmx.net>
	<CAEZATCXRWw9qnWFMrh-B+gbNuVNG3HKgpHgTY1kZ=OhdoGE1Wg@mail.gmail.com>
	<1671.1445890789@sss.pgh.pa.us>
	<CAEZATCXr7yioJHRXjgnu6f2W=tH5zuPtGmvxV0eT3WPgGKpSQg@mail.gmail.com>
	<5178.1445899865@sss.pgh.pa.us>
	<CAEZATCVZS+ccaEXNA-5qE=spk11Vtyxg8ePG_0RqpS1sjE==SA@mail.gmail.com>
	<CAEZATCV+6r0B1KG9KBFDY7K-9OyeAd5=UfwvR0YhGJgRJgWSOw@mail.gmail.com>
	<CAB7nPqS+wg+iWeL7pC1MS3ELmf4==XjJewH9_HPk+jx4NQ1E-g@mail.gmail.com>
	<CAB7nPqQ+KEtNXKUBNEzpOj4AESC8ipB3gUpgdbOb+b3KRgqzCw@mail.gmail.com>
	<CAEZATCW=tjGftAW44UcwpO419T83ZvdPC5vKH59WmDAA=7XjMw@mail.gmail.com>
	<CAEZATCUyVFyu2MFLk2uM28VQH2DmE=ryCuj8weBvyDOVe=8O2w@mail.gmail.com>
	<CAB7nPqQdichAyq3iNo_Ym9jgo6XkyuhivTV5tCG3E9Z_drCo6A@mail.gmail.com>
	<CAB7nPqRk+nNpJZ=AD8pG3305Bq9XwPrqEw4GUJhOk0XJ174W3w@mail.gmail.com>
	<31706.1448892680@sss.pgh.pa.us>
	<CAEZATCXO_ZVuj7xCco4GAFa_=KLJk3=aKnODLM47HB0SY=GKqw@mail.gmail.com>
	<11878.1453495831@sss.pgh! .pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

I wrote:
> Dean Rasheed <dean.a.rasheed@gmail.com> 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



view thread (57+ messages)  latest in thread

Message-ID: <21072.1453513223@sss.pgh.pa.us>
Permalink:  ../21072.1453513223@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21072.1453513223@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dean.a.rasheed@gmail.com, michael.paquier@gmail.com, peter_e@gmx.net
  Subject: Re: Proposal: Trigonometric functions in degrees
  In-Reply-To: <21072.1453513223@sss.pgh.pa.us>
  References: <CAEZATCXxdzxb2Mvi0-Xvp43tfvw-bUi703HdAJuLUd7dt5-ZgQ@mail.gmail.com> <562E82F7.2060704@gmx.net> <CAEZATCXRWw9qnWFMrh-B+gbNuVNG3HKgpHgTY1kZ=OhdoGE1Wg@mail.gmail.com> <1671.1445890789@sss.pgh.pa.us> <CAEZATCXr7yioJHRXjgnu6f2W=tH5zuPtGmvxV0eT3WPgGKpSQg@mail.gmail.com> <5178.1445899865@sss.pgh.pa.us> <CAEZATCVZS+ccaEXNA-5qE=spk11Vtyxg8ePG_0RqpS1sjE==SA@mail.gmail.com> <CAEZATCV+6r0B1KG9KBFDY7K-9OyeAd5=UfwvR0YhGJgRJgWSOw@mail.gmail.com> <CAB7nPqS+wg+iWeL7pC1MS3ELmf4==XjJewH9_HPk+jx4NQ1E-g@mail.gmail.com> <CAB7nPqQ+KEtNXKUBNEzpOj4AESC8ipB3gUpgdbOb+b3KRgqzCw@mail.gmail.com> <CAEZATCW=tjGftAW44UcwpO419T83ZvdPC5vKH59WmDAA=7XjMw@mail.gmail.com> <CAEZATCUyVFyu2MFLk2uM28VQH2DmE=ryCuj8weBvyDOVe=8O2w@mail.gmail.com> <CAB7nPqQdichAyq3iNo_Ym9jgo6XkyuhivTV5tCG3E9Z_drCo6A@mail.gmail.com> <CAB7nPqRk+nNpJZ=AD8pG3305Bq9XwPrqEw4GUJhOk0XJ174W3w@mail.gmail.com> <31706.1448892680@sss.pgh.pa.us> <CAEZATCXO_ZVuj7xCco4GAFa_=KLJk3=aKnODLM47HB0SY=GKqw@mail.gmail.com> <21072.1453513223@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox