Conversation
| const double Omega = 2.0 * Math.PI * nominalFreq; | ||
| int totalSamples = (int)(sampleRate / nominalFreq * 50); | ||
| long samplePeriodNs = (long)(1e9 / sampleRate); | ||
| double omega = 2.0 * Math.PI * nominalFreq; |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
In general, when a local variable is assigned but never read, either the variable should be removed (if it is genuinely unused) or the code should be corrected to actually use it (if it was intended to participate in the logic). Here, omega is the angular frequency derived from nominalFreq. Since no later code reads omega in the provided method, the best fix that preserves existing behavior is to remove the declaration/assignment of omega. This eliminates the useless assignment without changing any program logic, because nothing depended on omega.
Concretely, in src/Gemstone.PhasorProtocols/SelCWS/RollingPhaseEstimationTest.cs, within TestNominalFrequency(), delete the line that declares and assigns omega (line 56). No additional imports, methods, or definitions are needed, and no other lines need to change.
| @@ -53,7 +53,6 @@ | ||
| // Generate samples for 50 cycles worth of data | ||
| int totalSamples = (int)(sampleRate / nominalFreq * 50); | ||
| long samplePeriodNs = (long)(1e9 / sampleRate); | ||
| double omega = 2.0 * Math.PI * nominalFreq; | ||
| long epochNs = 0; | ||
|
|
||
| double lastFrequency = 0; |
| if (Math.Abs(sincArg) < 1e-15D) | ||
| sincVal = 1.0D; | ||
| else | ||
| sincVal = Math.Sin(sincArg) / sincArg; |
Check notice
Code scanning / CodeQL
Missed ternary opportunity Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
To fix the issue, replace the if/else block that only assigns to sincVal with a single assignment using the conditional (?:) operator. This will condense the logic into one line, better expressing that sincVal is chosen between two values based solely on the condition, without changing functionality.
Concretely, in src/Gemstone.PhasorProtocols/SelCWS/RollingPhaseEstimator.cs, in the M-class filter section inside the for (int i = 0; i <= N; i++) loop (around lines 670–675), remove the multi-line if (Math.Abs(sincArg) < 1e-15D) ... else ... that assigns to sincVal, and replace it with a single line:
double sincVal = Math.Abs(sincArg) < 1e-15D ? 1.0D : Math.Sin(sincArg) / sincArg;No new methods, imports, or definitions are required; this is a pure refactor of existing logic, keeping the exact same condition and branch expressions.
| @@ -667,13 +667,8 @@ | ||
| double k = i - N / 2.0D; | ||
| double sincArg = TwoPI * (2.0D * Ffr) / fs * k; | ||
|
|
||
| double sincVal; | ||
| double sincVal = Math.Abs(sincArg) < 1e-15D ? 1.0D : Math.Sin(sincArg) / sincArg; | ||
|
|
||
| if (Math.Abs(sincArg) < 1e-15D) | ||
| sincVal = 1.0D; | ||
| else | ||
| sincVal = Math.Sin(sincArg) / sincArg; | ||
|
|
||
| w[i] = sincVal * hamming[i]; | ||
| } | ||
| } |
…udes and m_publishAngles (which already have the nominal rotation removed)
This PR was Generated by a release of openHistorian