Skip to content

[AUD-014][High] Fix CORDIC periodic range reduction and atan2 zero vector #312

Description

@gabrielsantosphilips

Audit finding

  • ID: AUD-014
  • Status: Verified defect
  • Severity: High
  • Confidence: High
  • Audited revision: 2f479320d805a1f9f35ebe4afaaeeded48913a94

Problem

SineCosine() moves an angle toward the convergence interval by only one pi shift. Inputs outside roughly one period remain outside the CORDIC convergence domain. Arctangent2(0,0) is not handled explicitly.

Source:

{
const T pi{ std::numbers::pi_v<T> };
const T halfPi{ pi / T(2) };
T angle{ angleRadians };
T sinSign{ T(1) };
T cosSign{ T(1) };
if (angle > halfPi)
{
angle -= pi;
sinSign = T(-1);
cosSign = T(-1);
}
else if (angle < -halfPi)
{
angle += pi;
sinSign = T(-1);
cosSign = T(-1);
}
T x{ K };
T y{ T(0) };
T z{ angle };
for (std::size_t i = 0; i < Iterations; ++i)
{
T d{ (z >= T(0)) ? T(1) : T(-1) };
T pow2i{ T(1) / static_cast<T>(std::size_t(1) << i) };
T xNew{ x - d * y * pow2i };
T yNew{ y + d * x * pow2i };
z -= d * atanTable[i];
x = xNew;
y = yNew;
}
return SinCos{ sinSign * y, cosSign * x };
}

Reproduction

  • SineCosine(2*pi) returned approximately (-0.9851656, 0.1716062) instead of (0,1).
  • Arctangent2(0,0) returned approximately 1.7432562, contradicting the documented zero convention.

Acceptance criteria

  • Perform complete periodic range reduction before CORDIC iteration.
  • Define and implement the (0,0) atan2 behavior.
  • Constrain Iterations below the shift width.
  • Add multi-period, axis, zero-vector, and iteration-bound tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions