-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Correctness.ReviewCastOnIntegerDivisionRule(git)
Sebastien Pouliot edited this page Mar 2, 2011
·
1 revision
Assembly: Gendarme.Rules.Correctness
Version: git
This rule checks for integral divisions where the result is cast to a floating point type. It's usually best to instead cast an operand to the floating point type so that the result is not truncated.
Bad example:
public double Bad (int a, int b)
{
// integers are divided, then the result is casted into a double
// i.e. Bad (5, 2) == 2.0d
return a / b;
}
Good example:
public double Good (int a, int b)
{
// a double is divided by an integer, which result in a double result
// i.e. Good (5, 2) == 2.5d
return (double) a / b;
}
- This rule is available since Gendarme 2.2
You can browse the latest source code of this rule on github.com
Note that this page was autogenerated (3/17/2011 1:55:44 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!