C is equivalent to matlab sind and cosd

So, I am working with some conversion of matlab code to c code manually. I'm just wondering if there is c equivalent to the sind and cosd functions that I see in matlab code. I think this returns the answer in degrees, not the c sin and cos function, which gives the result in radians. I guess I could just multiply the result by 180 / pi, but it was just interesting if there is a library function in math.h I do not see. Or even if the gsl library has something similar.

+4
source share
5 answers

The H2CO3 solution will have a catastrophic loss of accuracy for large arguments due to the inaccuracy of the M_PI . General, safe version for any argument:

 #define sind(x) (sin(fmod((x),360) * M_PI / 180)) 
+9
source

No, trigonometric functions in the standard C library work in radians. But you can easily get away with a macro or a built-in function:

 #define sind(x) (sin((x) * M_PI / 180)) 

or

 inline double sind(double x) { return sin(x * M_PI / 180); } 

Note that the opposite conversion is necessary if you want to change the return value of the function (the so-called inverse or "arc" functions):

 inline double asind(double x) { return asin(x) / M_PI * 180; } 
+3
source

No, they are not available in the C library. You will only find the arguments of the radian values ​​or return the values ​​in the C library.

+1
source

Also note that sind and cosd, etc. do not return the result in degrees, they accept their arguments in degrees. These are asind and acosd, which return their results in degrees.

+1
source

Not in C library. All C trigonometric library functions accept arguments in the form of radian values ​​with no degree. As you said, you need to perform the conversion yourself or use a dedicated library.

0
source

All Articles