Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef M_PI
- #define M_PI (3.1415926535897932384626433)
- #endif
- #define M_PI2 (M_PI/2)
- #define M_2PI (2*M_PI)
- #define _fmod(_x, _y) ( (_x) - ( (long long)((_x)/(_y)) * (_y) ) )
- //(you could switch floats with doubles here, though the approximation's
- //lack of precision prevents that switch from being all that useful)
- float sinf_bhaskara(float x){
- //keep x within the domain of >=0 -> <pi,
- //while preserving relevant info
- char negative = x<0.0f;
- if(x < 0.0f) x = -x; //x = fabsf(x);
- x = _fmod(x, M_2PI); //x %= 2pi
- //'if original value of x%(2pi) is between _ -> _, returned value will be _':
- //>-2pi -> <=-pi, >=0
- //> -pi -> <= 0, <=0
- //>= 0 -> < pi, >=0
- //>= pi -> < 2pi, <=0
- negative ^= x>=M_PI;
- if(x >= M_PI) x -= M_PI; //x %= pi
- float result = 16*x * (M_PI-x);
- result /= 5*M_PI*M_PI - 4*x*(M_PI-x);
- return (negative) ? -result : result;
- }
- #define sinf sinf_bhaskara
- #define cosf(_x) sinf((_x)+M_PI2)
- #define tanf(_x) ( sinf(_x)/cosf(_x) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement