Created
October 24, 2013 05:16
-
-
Save shonenada/7131734 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define PI 3.1415926535898 | |
#define sqrt2 1.41421356237 | |
double fabs(double input){ | |
return input > 0 ? input : (-input); | |
} | |
double get(double sinVal, double cosVal){ | |
int correct; | |
int coefficient; | |
if (cosVal > 0 && sinVal > 0){ | |
correct = 0; | |
coefficient = 1; | |
} | |
else if (cosVal < 0 && sinVal > 0){ | |
correct = 180; | |
coefficient = -1; | |
} | |
else if (cosVal < 0 && sinVal < 0){ | |
correct = 180; | |
coefficient = 1; | |
} | |
else if (cosVal > 0 && sinVal < 0){ | |
correct = 0; | |
coefficient = -1; | |
} | |
sinVal = fabs(sinVal); | |
cosVal = fabs(cosVal); | |
int i, j; | |
double prev, diff; | |
const double sinK[5] = {0.0173648177667, 0.0168371965659, | |
0.0157979856674, 0.0142787609687, | |
0.0123256833432}; | |
const double sinB[5] = {0.0, 0.00527621200819, 0.026060429977, | |
0.0716371709404, 0.149760275957}; | |
const double sinSep[6] = {0, 0.174522183226460, 0.342020143325669, | |
0.5, 0.642787609686539, 0.766044443118978}; | |
const double cosK[5] = {-0.0142787609687, -0.0157979856674, | |
-0.0168371965659, -0.0173648177667, | |
-0.0173648177667}; | |
const double cosB[5] = {1.35672565812, 1.44787914005, 1.52062390294, | |
1.562833599, 1.562833599}; | |
const double cosSep[6] = {0.642787609687, 0.5, 0.342020143326, | |
0.173648177667, 6.12323399574e-17, 0}; | |
for (i=0;i<5;i++) | |
if (sinSep[i] <= sinVal && sinVal < sinSep[i+1]) | |
return coefficient * ((sinVal - sinB[i]) / sinK[i]) + correct; | |
for (i=0;i<5;i++) | |
if (cosSep[i+1] < cosVal && cosVal <= cosSep[i]) | |
return coefficient * ((cosVal - cosB[i]) / cosK[i]) + correct; | |
return -1; | |
} | |
int main(){ | |
double s; | |
double c; | |
scanf("%lf", &s); | |
scanf("%lf", &c); | |
printf("%lf", get(s, c)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment