Re: no tests for trigonometric functions? need help / hints how to adapt tests for gnumeric 'long' version,



On 5/29/22 12:59 AM, Steven D'Aprano asked:

Can you point me at the source code for cospi please?

In addition to my previous answer, here is an answer that
is perhaps more appropriate to this forum. Here's how it's
done in gnumeric (more specifically goffice):
  https://gitlab.gnome.org/GNOME/goffice/-/blob/master/goffice/math/go-math.c#L1073

It assumes you already have an implementation of plain
sin() and cos().

To compute sinpi(x), it first calculates xprime which is
the remainder of x modulo 0.25, then uses trig identities
plus the library routines for sin() and cos() applied
to xprime*M_PI.

The idea is that since xprime is small, multiplying it
by M_PI doesn't do much damage.

Here's my previous answer, which uses only algebraic
operations (multiply and add), as I mentioned back on
5/29/22 7:46 AM.
For years I've been using the code discussed here:
   
https://stackoverflow.com/questions/42792939/implementation-of-sinpi-and-cospi-using-standard-c-math-library

It might be amusing to compare the various approaches
in terms of accuracy and efficiency.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]