MikeLankamp / fpm

C++ header-only fixed-point math library
https://mikelankamp.github.io/fpm
MIT License
649 stars 79 forks source link

feat: improve accuracy for atan2(y,x) when x is near-zero #19

Closed MikeLankamp closed 3 years ago

MikeLankamp commented 3 years ago

atan2(y,x) requires a lot of bits in the integer part when x is near-zero. This is because atan2(y,x) does atan(y/x) internally and y/x easily overflows for very small x unless you have more integer bits than fraction bits. However, atan(q) does 1/q if q > 1, thereby inverting the original division in atan2. So this overflow can be avoided if these divisions are shortcut.

Closes #18