Numeric Coercion Risks
Detects implicit numeric conversions that risk truncation, overflow, or loss of precision. Flags unchecked downcasts, float-to-int conversions, and assignments from large types to small types.
Why this rule exists
Numeric truncation is silent. An int cast from a long value that exceeds Int32.MaxValue wraps around without warning. Precision loss in float-to-int conversions causes calculations to diverge. checked{} throws on overflow, making the failure visible.
Code example
+ int size = collection.Length; // Length is long, could truncate
+ int ratio = (int)(totalRatio * 100); // float to int precision loss+ int size = checked((int)collection.Length); // throws on overflow
+ decimal ratio = (decimal)totalRatio * 100; // use decimal for precisionConfiguration
Disable or adjust the severity of this rule in .gauntletci.json:
{
"rules": {
"GCI0051": { "enabled": true, "severity": "Warn" }
}
}See Configuration for the full schema.
Related rules
Float and Double Equality Comparison
Detects direct equality (== / !=) comparisons involving floating-point values, which produce unreliable results due to precision loss.
Data Integrity Risk
Detects unchecked casts, mass assignment without validation, and SQL ON CONFLICT IGNORE patterns that silently discard errors.
Implemented in src/GauntletCI.Core/Rules/Implementations/GCI0051_*.cs.
Eric Cogen -- Founder, GauntletCI
Twenty years as a senior technical consultant building and modernizing enterprise platforms across .NET, AWS, serverless, microservices, and AI-driven systems.
