Fastest implementation of sine, cosine and square root in C++ (doesn’t need to be much accurate)

Here’s the guaranteed fastest possible sine function in C++: double FastSin(double x) { return 0; } Oh, you wanted better accuracy than |1.0|? Well, here is a sine function that is similarly fast: double FastSin(double x) { return x; } This answer actually does not suck, when x is close to zero. For small x, … Read more

Endless sine generation in C

Instead of calculating sine as a function of time, maintain a sine/cosine pair and advance it through complex number multiplication. This doesn’t require any trigonometric functions or lookup tables; only four multiplies and an occasional re-normalization: static const double a = 2 * M_PI * 280 * 30e-6; static const double dx = cos(a); static … Read more

How does C compute sin() and other math functions?

In GNU libm, the implementation of sin is system-dependent. Therefore you can find the implementation, for each platform, somewhere in the appropriate subdirectory of sysdeps. One directory includes an implementation in C, contributed by IBM. Since October 2011, this is the code that actually runs when you call sin() on a typical x86-64 Linux system. … Read more

How to use the PI constant in C++

On some (especially older) platforms (see the comments below) you might need to #define _USE_MATH_DEFINES and then include the necessary header file: #include <math.h> and the value of pi can be accessed via: M_PI In my math.h (2014) it is defined as: # define M_PI 3.14159265358979323846 /* pi */ but check your math.h for more. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)