How could I define trigonometric functions that take arguments in degrees instead of regular radians and calculate correctly rounded results for these arguments?
Multiplying the argument by M_PI/180.0 before passing its corresponding function in radians does not work, because M_PI/180.0 not π / 180. Section 5.5 of the Floating Point Arithmetic Handbook offers a method for calculating the correctly rounded product of an argument by π / 180, but some arguments will still be such that this product is close to the middle between two consecutive represented floats, and then applying even a correctly rounded function in radians may lead to an incorrect final result.
Two strategies that can work independently or in combination, use higher accuracy and use the trigonometric functions sinpi , cospi , tanpi from CRlibm , which calculate sin(πx) , cos(πx) and tan(πx) , respectively.
For the latter strategy, the problem of dividing by 180 remains, which is not accurate for many arguments.
As for the strategy with higher accuracy (multiplying the argument by a representation with extended accuracy π / 180, then applying the function of extended accuracy in radians), there may be a problem with “exact” cases. The theorem that the only rational results sin , cos and tan for a rational argument obtained at 0 applicable only to radian versions. Obviously this does not apply to degree versions, and if for some floating-point input x, sindeg (x) is exactly the middle between two consecutive represented floating-point numbers, then the intermediate precision is not enough to ensure that the final result is correctly rounded .
floating-point trigonometry
Pascal cuoq
source share