Hi,
I assume that you are using single precision floating-point arithmetic. Trigonometric functions from the standard math.h library usually sacrifice performance to achieve high accuracy over the entire floating-point range.
The Automotive Math and Motor Control Library (AMMCLib) provides speed-optimized trigonometric functions for applications where the angle is limited to one revolution (i.e. ±π radians) and the accuracy of results does not need to be much higher than the resolution of the A/D converters. AMMCLib also provides a combination of sine and cosine in one function (GFLIB_SinCos) which further reduces the clock cycles. AMMCLib trigonometric functions don't rely on table look-up so the memory footprint remains minimal.
| Function |
Input range |
Accuracy of results |
Max. CPU clock cycles on MPC5777C with a commercial compiler |
| GFLIB_Cos_FLT |
±π |
error max. ±42 ulp |
45 |
| GFLIB_Sin_FLT |
±π |
error max. ±42 ulp |
56 |
| GFLIB_SinCos_FLT |
±π |
error max. ±42 ulp |
81 |