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))

n is undefined. I do not understand your int statement. I would index a tuple of the values instezd of
nested if.. Sorry but mobile posting is not working at the moment correctly.

Could you post the error you are getting and how you are using the function.

quad = int(x[ quad])

I chnage to quad = int( quad]) Still there no output Di I need print statement basiclly

Your logic does not seem to function as I am getting error of almost 2 for
cos(3.14): -1 vs +1

Yeh It seem like no working :(

BTW, how do you copy and paste the new DaniWeb code areas?

include <stdio.hu

int maintint orge, const char * argv(1) (

int t,t, n ,count-0; for (int i=0; i<t; 1++) {

printf("enter");

scanf("%d",&t);

scanf("%d %d %d",&x,ay, &n);

X ;

for (int i=0; x<n; i++) { if (x<n) {

count++;

)

if (x<n)

Inbox (46) sukant20.

printf("%d",count)

return O

commented: Poor formatting, 8 years late. -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.