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
Audit finding
AUD-0142f479320d805a1f9f35ebe4afaaeeded48913a94Problem
SineCosine()moves an angle toward the convergence interval by only onepishift. Inputs outside roughly one period remain outside the CORDIC convergence domain.Arctangent2(0,0)is not handled explicitly.Source:
numerical-toolbox-cpp/numerical/math/Cordic.hpp
Lines 84 to 121 in 2f47932
Reproduction
SineCosine(2*pi)returned approximately(-0.9851656, 0.1716062)instead of(0,1).Arctangent2(0,0)returned approximately1.7432562, contradicting the documented zero convention.Acceptance criteria
(0,0)atan2 behavior.Iterationsbelow the shift width.