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: Emre Hasegeli <emre@hasegeli.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Proposal: Trigonometric functions in degrees
Date: Mon, 26 Oct 2015 14:58:09 -0400
Message-ID: <32497.1445885889@sss.pgh.pa.us> (raw)
In-Reply-To: <CAEZATCV+rkuA23ceYS_VA2UXLX7X4L-fkOOh8zhFX67r6YmhkQ@mail.gmail.com>
References: <CAEZATCXxdzxb2Mvi0-Xvp43tfvw-bUi703HdAJuLUd7dt5-ZgQ@mail.gmail.com>
	<CAE2gYzyXyeBDA_nAVNAqmqUx_ouY1QVEim8gQrf4m=ict4wt1A@mail.gmail.com>
	<CAEZATCWT1JVX-XeT8ghFNn84DytZ-Rw+8dZ3=u1AftM9ZerXCw@mail.gmail.com>
	<26314.1445869112@sss.pgh.pa.us>
	<CAEZATCV+rkuA23ceYS_VA2UXLX7X4L-fkOOh8zhFX67r6YmhkQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Dean Rasheed <dean.a.rasheed@gmail.com> writes:
> On 26 October 2015 at 14:18, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> ... but having said that, your argument here is faulty, because 0.9
>> in itself is not exactly representable in binary.  You'd be relying
>> on roundoff happening in the right direction to get exact answers
>> from such calculations, for just the same reasons that sind() can't be
>> just "sin(x * scalefactor)" if you want exact-where-possible results.

> It would be relying on the things like the following being exactly true:

> 45 / 0.9 = 50
> 50 * 0.9 = 45
> 90 / 0.9 = 100
> 100 * 0.9 = 90

> which they are on my machine. I thought that this was guaranteed in
> IEEE floating point arithmetic, since one of the inputs and the result
> are exactly representable, and the result is guaranteed to be within
> 0.5ulp. I'm curious now though. Are there any platforms on which the
> above aren't exactly true?

Possibly, but the bigger picture is you're ignoring other cases, such as

regression=# select 30 / 0.9;
      ?column?       
---------------------
 33.3333333333333333
(1 row)

which is problematic since sin(30 degrees) = 0.5 is one of the cases
one would like to be exact.  (Actually I guess this example shows that
implementing sind in terms of sing would be imprecise, but I'm sure
the reverse holds for some other special angles.)

			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: <32497.1445885889@sss.pgh.pa.us>
Permalink:  ../32497.1445885889@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/32497.1445885889@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, emre@hasegeli.com
  Subject: Re: Proposal: Trigonometric functions in degrees
  In-Reply-To: <32497.1445885889@sss.pgh.pa.us>
  References: <CAEZATCXxdzxb2Mvi0-Xvp43tfvw-bUi703HdAJuLUd7dt5-ZgQ@mail.gmail.com> <CAE2gYzyXyeBDA_nAVNAqmqUx_ouY1QVEim8gQrf4m=ict4wt1A@mail.gmail.com> <CAEZATCWT1JVX-XeT8ghFNn84DytZ-Rw+8dZ3=u1AftM9ZerXCw@mail.gmail.com> <26314.1445869112@sss.pgh.pa.us> <CAEZATCV+rkuA23ceYS_VA2UXLX7X4L-fkOOh8zhFX67r6YmhkQ@mail.gmail.com> <32497.1445885889@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