38 lines
759 B
C
38 lines
759 B
C
#include <stdio.h>
|
|
#include <math.h>
|
|
|
|
// double PI = 3.141592653589793;
|
|
|
|
// double wrap_angle(double x) {
|
|
// while (x > PI) x -= 2*PI;
|
|
// while (x < -PI) x += 2*PI;
|
|
// return x;
|
|
// }
|
|
|
|
// double my_sin(double x) {
|
|
// x = wrap_angle(x);
|
|
|
|
// double x2 = x * x;
|
|
// return x
|
|
// - (x * x2) / 6
|
|
// + (x * x2 * x2) / 120
|
|
// - (x * x2 * x2 * x2) / 5040;
|
|
// }
|
|
|
|
int my_cos(int x) {
|
|
x *= x;
|
|
return 1 - x/2 * (1 - x/12 * (1 - x/30 * (1 - x/56 * (1 - x/90))));
|
|
}
|
|
|
|
int main(void) {
|
|
// const double PI = 3.141592653589793;
|
|
|
|
int x = my_cos(3);
|
|
|
|
// printf("%f\n", cos(3));
|
|
// printf("%f\n", cos(-3));
|
|
// printf("%f\n", cos(0));
|
|
// printf("%f\n", cos(PI));
|
|
// printf("%f\n", cos(PI / 2.0));
|
|
return 0;
|
|
} |