#include "maths.h" //get the value of sin/cos(dir * pi_4) float fcos(unsigned char x) { float cos[4] = {1.0, 0.707106, 0.0, -0.707106}; return (x < 4 ? cos[x] : - cos[x%4]); } float fsin(unsigned char x) { return fcos(x - 2); } #define MAX_TURN 6 float cos(float x) { unsigned int a = 8 * MAX_TURN - 6; unsigned int b = 2 * MAX_TURN * (2 * MAX_TURN - 1); // 2n(2n-1) float s = 1; unsigned short i; x = x * x; // x² for(i = 0; i < MAX_TURN; i++) { s = 1 - x * s / b; b -= a; a -= 8; } return s; } float sin(float x) { return cos(x - pi_2); }