Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve fixed-point tangent calculation for division-less operations and accuracy #33

Open
jouae opened this issue Aug 10, 2024 · 1 comment

Comments

@jouae
Copy link
Collaborator

jouae commented Aug 10, 2024

When calculating the twin_tan(), division is used, specifically $\frac{\sin x}{\cos x}$

// twin_tan()
return ((s << 15) / c) << 1;

To minimize the use of the division operator, you can refer to the division implementation mentioned in https://hackmd.io/@sysprog/linux-intdiv, which describes the implementation in jemalloc to avoid direct use of the division operator.

Currently, testing and experimental data are needed to confirm that using this division method in twin_tan within mado can achieve faster calculation times.

As for the other issue, it's whether twin_tan can be improved further, including enhancements in precision and calculation speed.

Perhaps coordinate rotation digital computer(CORDIC) cloud be a solution.

The note here provide a quick overview of the mathematical principles behind conventional CORDIC and scaling-free CORDIC.

Reference:

  1. https://hackmd.io/@sysprog/linux-intdiv
  2. https://github.com/Max-Gulda/Cordic-Math
  3. https://hackmd.io/@jouae/mado_trig
@jserv jserv changed the title Improve the twin_tan Improve fixed-point tangent calculation for division-less operations and accuracy Aug 11, 2024
@jouae
Copy link
Collaborator Author

jouae commented Sep 7, 2024

An array architecture for fast computation of discrete Hartley transform by A. S. Dhar and S. Banerjee, 1991, mentions the use of small-angle approximations for sine and cosine functions to compensate for the need for a scaling factor $K$.

In the method, a magic number $(n−2.852)/3$ is referenced, where this magic number imposes the restriction that the number of bits shifted $j$ in the iteration must be greater than $\left\lceil \frac{n-2.585}{3} \right\rceil$.

This magic number is derived from the error estimation obtained from the remainder terms of the Taylor series approximation for sine and cosine functions. If the initial number of shifted bits $j$ does not exceed this magic number, the result of the approximation will not be accurate.

The detailed derivation process is recorded in the note: Scaling-free method of CORDIC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant