SPRAD27A July   2022  – August 2022 AM2431 , AM2432 , AM2434 , AM2631 , AM2631-Q1 , AM2632 , AM2632-Q1 , AM2634 , AM2634-Q1 , AM2732 , AM2732-Q1 , AM6411 , AM6412 , AM6421 , AM6422 , AM6441 , AM6442

 

  1.   Abstract
  2.   Trademarks
  3. 1Introduction
  4. 2Trigonometric Optimizations
    1. 2.1 Lookup Table-Based Approximation
    2. 2.2 Polynomial Approximation
      1. 2.2.1 Optimizing Sine and Cosine
        1. 2.2.1.1 Sine Cosine Polynomials From Sollya
      2. 2.2.2 Optimizing Arctangent and Arctangent2
        1. 2.2.2.1 Arctangent Polynomials
  5. 3Trig Library Benchmarks
    1. 3.1 C Math.h Library
    2. 3.2 Arm “Fast Math Functions” in CMSIS
    3. 3.3 TI Arm Trig Library
    4. 3.4 Table of Results
  6. 4Optimizations
    1. 4.1 Branch Prediction
    2. 4.2 Floating-Point Single-Precision Instructions
    3. 4.3 Memory Placement
    4. 4.4 Compiler
  7.   Revision History

Sine Cosine Polynomials From Sollya

Table 2-1 and Table 2-2 show the coefficients for the sine and cosine approximation obtained from the Sollya program. The table shows the error expected given the range reduction and order of the polynomial. If you are trying to achieve full single precision floating-point accuracy, then you need to get to ~1e-7.

Table 2-1 Sine
Range Number of Terms Absolute Error Polynomial
−π/2 : π/2 3 1.00E-04
Equation 8. x * (0.999891757965087890625 + x2 * (-0.165960013866424560546875 + x2 * 7.602870464324951171875e-3))
−π/2 : π/2 4 6.00E-07
Equation 22. x * (0.999996483325958251953125 + x2 * (-0.166647970676422119140625 + x^2 * (8.306086063385009765625e-3 + x2 * (-1.83582305908203125e-4))))
−π/2 : π/2 5 6.00E-09
Equation 10. x * (1 + x2 * (-0.1666665971279144287109375 + x2 * (8.333069272339344024658203125e-3 + x2 * (-1.98097783140838146209716796875e-4 + x2 * 2.6061034077429212629795074462890625e-6))))
−π/4 : π/4 2 1.50E-04
Equation 11. x * (0.99903142452239990234375 + x2 * (-0.16034401953220367431640625))
−π/4 : π/4 3 5.60E-07
Equation 12. x * (0.9999949932098388671875 + x2 * (-0.166601598262786865234375 + x2 * 8.12153331935405731201171875e-3))
−π/4 : π/4 4 1.80E-09
Equation 13. x * (1 + x2 * (-0.166666507720947265625 + x2 * (8.331983350217342376708984375e-3 + x2 * (-1.94961365195922553539276123046875e-4))))
−π/4 : π/4 5 6.00E-11
Equation 14. x * (1 + x2 * (-0.16666667163372039794921875 + x2 * (8.33337195217609405517578125e-3 + x2 * (-1.98499110410921275615692138671875e-4 + x2 * 2.800547008519060909748077392578125e-6))))
Table 2-2 Cosine
Range Number of Terms Absolute Error Polynomial
−π/2 : π/2 3 6.00E-04
Equation 15. 0.9994032382965087890625 + x2 * (-0.495580852031707763671875 + x2 * 3.679168224334716796875e-2)
−π/2 : π/2 4 6.70E-06
Equation 16. 0.99999332427978515625 + x2 * (-0.4999125301837921142578125 + x2 * (4.1487820446491241455078125e-2 + x2 * (-1.27122621051967144012451171875e-3)))
−π/2 : π/2 5 6.00E-08
Equation 17. 0.999999940395355224609375 + x2 * (-0.499998986721038818359375 + x2 * (4.1663490235805511474609375e-2 + x2 * (-1.385320327244699001312255859375e-3 + x2 * 2.31450176215730607509613037109375e-5)))
−π/4 : π/4 3 1.00E-05
Equation 18. 0.999990046024322509765625 + x2 * (-0.4997082054615020751953125 + x2 * 4.03986163437366485595703125e-2)
−π/4 : π/4 4 3.30E-08
Equation 19. 1 + x2 * (-0.49999892711639404296875 + x2 * (4.16561998426914215087890625e-2 + x2 * (-1.35968066751956939697265625e-3)))
−π/4 : π/4 5 1.00E-10
Equation 20. 1 + x2 * (-0.5 + x2 * (4.16666455566883087158203125e-2 + x2 * (-1.388731296174228191375732421875e-3 + x2 * 2.4432971258647739887237548828125e-5)))