Octave (or Matlab) & C
The approach is to generate approximating quadratic polynomial for each degree. So degree = [0, 1), degree = [1, 2), etc. degree = [359, 360) each have a different polynomial.
The maximum absolute error for sin
and cos
was < 1e-08. For tan
, because the result isn't limited to ± 1 and you can divide a relatively large number by a relatively small number, the absolute error could be larger, but the. The maximum relative error, e.g. fabs((actual - result) / actual)
for |actual| > 1
was usually < 2e-08 until you get in the area of (90 ± 5) or (270 ± 5) degrees, then the error gets worse.
In testing, the average time per single input was (1.053 ± 0.007) µs, which on my machine was about 0.070 µs faster than native sin
and cos
, tan
being defined the same way.