Search code examples
cmathtrigonometryoperations

Conversion of Degrees to Radians for use in trig functions in C


I want to use the trigonometric functions of math.h to use 0,1,-1 as sign identifiers for a plane coordinate system.

cos(pi)*length = -1*length
sin(pi)*length = 0

But the functions in math.h requires radian values while I have degree values. Although these can be converted in the formulas I don't know it it will affect the accuracy of the answers i.e. cos(pi) = -0.99999..

Will this affect the operations on my code?

EDIT: What can I do to get my desired results?


Solution

  • They probably will affect the accuracy by the precision to which you have pi - usually one unit in the last place. For cos and sin, |d f(x)/dx| is less than one so your value should be within the same error. For tan, |d f(x)/dx| is not bounded so a small input change can create a large change of output.

    Whether such small changes will affect the operation of your code depends largely on whether your code assumes than the results are exact or not. If your code makes faulty assumptions about floating point values, then it will fail, if it allows some small tolerance on equality comparisons, then it wont.