Dean Rasheed <dean.a.rash...@gmail.com> writes: > On 26 October 2015 at 19:45, Peter Eisentraut <pete...@gmx.net> wrote: >> But how you are going to implement that? I don't see a sind() in the C >> library.
> I'm thinking something along the lines of: > 1. Reduce the range of the input (say to 0..90 degrees). > 2. Handle special cases (0, 30 and 90 for sind()). > 3. Otherwise convert to radians for the general case. I'd be okay with #1 and #3, but #2 is just a crock; it would risk creating problems that did not exist before, such as non-monotonicity of the function result (over ranges where that does not hold). I looked into my dusty old copy of Cody & Waite's "Software Manual for the Elementary Functions", which is what I used as a reference the last time I had to do code like this (which admittedly was quite a long time ago; the state of the art might've advanced). C&W say that the key accuracy limit for sin and cos is reduction of the argument modulo pi (or whichever multiple of pi you choose to work with). Now that problem just goes away for degrees, of course, so it might be that reduction mod 360 and then conversion to radians would be Good Enough(TM). If it's not good enough, a possible idea is reduction mod 45 degrees or even mod 30 degrees and then using trig identities to reconstruct the correct output. Anyway, I think the core idea of trying to build a reasonably thin wrapper around sin(3m) and friends is probably an appropriate amount of effort, depending on how many cases you are hoping to make exact. I doubt it's worth coding sind() from scratch. 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