mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 04:58:08 +00:00
Add exact-zero guards in various classes to prevent division by zero errors
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user