BigUglySpider / EmuLibs

Selection of libraries designed to be used with Emu projects. This was originally a Math library only, but has since been changed to hold all Emu libraries to enable consistency in changes to dependencies (such as EmuCore modifications).
https://biguglyspider.github.io/math
0 stars 0 forks source link

[EmuCore] Trigonometric functions using Taylor Series approach should be reworked #52

Open BigUglySpider opened 2 years ago

BigUglySpider commented 2 years ago

When working with making constexpr-evaluable acos, asin, and atan/atan2 functions, it became clear how inaccurate the current approach can be, and a different approach was taken.

acos, asin, and atan/atan2 use reference material from the NVIDIA developer site to calculate approximations instead. These approximations remain liable for imprecision, but cover the following bases:

  1. Reduced verbosity - no need for NumIterations_ and DoMod_ arguments since we have a fixed calculation size and a fixed series of calculations.
    • This also opens up easier adaptation for specialisations since they don't need to consider 3 arguments, only the 1 type argument
  2. Increasing imprecision is corrected for the edges of certain ranges, such as is the case for the inverse functions when approaching the edge of the -1:1 range.
  3. Makes constexpr-specialised functions common to EmuMath types and templates more streamlined and less fiddly.
    • With this in mind, it does also mean significant care will have to be taken in removal as all mentions of NumIterations_ and DoMod_ will need to be cleared, including in templates where they are not obviously being used for the sake of automatic text searching.
  4. The point of EmuMath is to optimise but hide the lower-level segments; exposing iteration count and the like drew this a bit close to the lower-level decision making which EmuMath aims to put behind the scenes.
  5. Consistency. A major drawback of the iterative methods is that there is no guarantee for arbitrary values when it comes to precision; 3 iterations could be perfectly fine for one value, but far too imprecise for another. This requires that the user always knows what values will be close to when deciding on iteration count, which is not particularly practical for the long run.

One can review the NVIDIA cg reference material (link to atan2) for an idea of how to adapt the functions to be consistent with their inverse variants.

BigUglySpider commented 1 year ago

Updated approach to this has been added for EmuSIMD functions in the changes for Linux, so the logic just needs to be translated from there for generic scalar arithmetic