Reputation: 35
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?
Upvotes: 1
Views: 691
Reputation: 153458
Will this affect the operations on my code?
When conversion is exact between degree/radians, not a problem. Of course this only happens when the angle is +/- 0.0.
To use trig function and get exact trig function result (or at least nearly as good as one can get) with degree arguments, insure the degree argument is reduced (mod 360
) first and then converted to radians. Further improvements can be had using trig identities: high precession and Sin and Cos
Upvotes: 1
Reputation: 49311
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.
Upvotes: 1