sin cos calculations, high precision library

hello
--I have not been able to find the answer as to how the sin and cos functions are calculated in math.h, is this done with the taylor series? or is it somehow read from stored values like a distribution?

--where can i the easiest see the details of algorithms used for math.h?

--does anyone have a recommendation for a library which makes it possible to include integers and floats of a higher precision than 64 bit?

thank you very much
v
I don't THINK they are calculated in math.h, I'm pretty sure that (for at least GCC) sinx is calculated simply by passing the assembler instruction fsinx to the processing unit.

I just got this from a quick google search, here is one of the pages I looked at (double check yourself):
http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

is this done with the taylor series? or is it somehow read from stored values like a distribution?

Both your guess are correct, I think. The calculation in most implementations nowadays relies on co-processor instructions and it is done by set of pre-calculated points interpolated with formulas like Taylor or Fourier for example.

However it is platform-dependent - that is why you could not find exact answer - on some platforms it could be software library - though on most it relies on (co)processor as I've told.


does anyone have a recommendation for a library which makes it possible to include integers and floats of a higher precision than 64 bit

Could you explain why you may need it, by the way? Note that existing precision is sufficient to calculate elements of Earth orbit up to 1 millimeter. Do you really need some precision? Perhaps you just mishandle your calculations somehow?
From Wikipedia:

The C standard library defines sine functions within math.h: sin(double), sinf(float), and sinl(long double). The parameter of each is a floating point value, specifying the angle in radians. Each function returns the same data type as it accepts.


EDIT: You might also want to read this:
http://stackoverflow.com/questions/2284860/how-does-c-compute-sin-and-other-math-functions
Last edited on
The C standard library defines sine functions


Key word: Defines, NOT implements

As in, it specifies the existence of a sin function, but not necessarily the implementation of it.
@ NT3: Thanks for correcting me :).

@vilbjorg: A library: https://gmplib.org/
Last edited on
thank you all very for the fast answers. I first of all need c++ to program objects that work within higerlevel sound-programming environments such as SuperCollider and ChucK. I need the library for a special project which is programmed in finite fields, and 64 bit integers are not enough , I have reached the limitation. The GMPlib looks like a very fine option. I am on macOS and linux.
The questions about the trig functions are with respect to being able to make processing as cpu-inexpensive as possible. I have for instance been working on programming a circular wave (sine) without the use of transcendentals as sin or cos, using an ancient parametrization of the circle combined with the algebra of complex numbers (suggested by mathematician NJ Wildberger) it takes less than 10 multiplications per new value in the rotation. Slowly trying to find my way comparing these things. But since things are happening a such different levels that will take quite a bit of studying i guess. thanks for links.
v
Last edited on
Topic archived. No new replies allowed.