RobTillaart / FastTrig

Arduino library with interpolated lookup for sin() and cos()

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

investigate itan()

RobTillaart opened this issue · comments

itan() is a difficult to optimize, especially on AVR. For ESP32 it works quite well.

  • lookup table has interpolation problems: above 60 degrees one cannot interpolate linear
    multiple lookup tables might be an option but that will kill performance on AVR even more.

  • investigate other strategies?

insight

  • tan(x) = 1/tan(PI/2 -x)
  • tan(x) = -tan(-x)

So only a table 0..45 degrees is needed = 46 values.

note this insight says nothing about performance, only about the interpolating precision.

some investigations done

tan(x) = 1/tan(PI/2 -x)

  • is slower
  • is equally precise
  • can be emulated by tan = 1 / (cos / sin)

tan(x) = -tan(-x)

  • is already used to handle negative values

made the %180 conditional in the itan(), at least that speeds up the math for 0..360°

==> update in github.