Hi, I try to convert the c code into python it actually complie but no result came out
Code in C
#include <stdio.h>
# include <math.h>
double const pi=3.1415926535897932384626433;
double const twopi=2.0*pi;
double const halfpi=pi/2.0;
float cos_32(float x)
{
int quad;
x=fmod(x,twopi);
if (x<0)
{
x=-x;
}
quad=int(x/halfpi);
switch (quad)
{
case 0:
return cos_32s(x);
break;
case 1:
return cos_32s(pi-x);
break;
case 2:
return cos_32s(x-pi);
break;
case 3:
return cos_32s(twopi-x);
break;
}
}
float cos_32s( float x)
{
float c1= 0.99940307;
float c2= -0.49558072;
float c3=0.03679168;
float x2;
x2= x * x;
return (c1 + x2 *(c2 + c3 * x2));
}
Code in Python
pi=3.1415926535897932384626433
twopi=2.0*pi
halfpi=pi/2.0
def cos_32(x):
x = math.fmod(x, twopi)
if (x<0):
x=-x
quad = x/halfpi
quad = int(x[ quad])
if quad == 0:
return cos_32s(x)
elif n== 1:
return cos_32s(pi-x)
elif n == 2:
return cos_32s(x-pi)
elif n== 3:
return cos_32s(twopi-x)
def cos_32s(x):
c1= 0.99940307
c2= -0.49558072
c3=0.03679168
x2= x * x
return (c1 + x2 *(c2 + c3 * x2))