Add exact-zero guards in various classes to prevent division by zero errors

This commit is contained in:
Miha Kralj
2026-02-16 21:57:11 -08:00
parent 63ae2c9ab2
commit b63b9730e1
10 changed files with 18 additions and 2 deletions
+2
View File
@@ -329,6 +329,7 @@ public sealed class Bbs : ITValuePublisher
_prevSqueezeOn = squeezeOn;
// === Bandwidth ===
// skipcq: CS-R1077 - Exact-zero guard: bbMean is a price average; zero means no data, not rounding artifact
double bandwidth = bbMean != 0.0 ? ((bbUpper - bbLower) / bbMean) * 100.0 : 0.0;
// === Resync for floating-point drift ===
@@ -611,6 +612,7 @@ public sealed class Bbs : ITValuePublisher
squeezeOn[i] = bbUpper < kcUpper && bbLower > kcLower;
// Bandwidth
// skipcq: CS-R1077 - Exact-zero guard: bbMean is a price average; zero means no data, not rounding artifact
bandwidth[i] = bbMean != 0.0 ? ((bbUpper - bbLower) / bbMean) * 100.0 : 0.0;
}
}
+2
View File
@@ -147,6 +147,7 @@ public sealed class Cfo : AbstractBase
double tsf = Math.FusedMultiplyAdd(slope, _period - 1, intercept);
// CFO = 100 * (source - tsf) / source
// skipcq: CS-R1077 - Exact-zero guard: value is a price; zero means no data, division by zero produces Infinity
double cfo = value == 0.0 ? double.NaN : 100.0 * (value - tsf) / value;
Last = new TValue(input.Time, cfo);
@@ -304,6 +305,7 @@ public sealed class Cfo : AbstractBase
double intercept = (sumY - slope * sumX) / period;
double tsf = Math.FusedMultiplyAdd(slope, period - 1, intercept);
// skipcq: CS-R1077 - Exact-zero guard: val is a price; zero means no data, division by zero produces Infinity
output[i] = val == 0.0 ? double.NaN : 100.0 * (val - tsf) / val;
}
}