Add IntegerDivisionRoundingAwayFromZero.
This provides the mirror of the integer division operator, which rounds towards zero.
This commit is contained in:
@@ -327,6 +327,15 @@ namespace OpenRA
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int IntegerDivisionRoundingAwayFromZero(int dividend, int divisor)
|
||||||
|
{
|
||||||
|
int remainder;
|
||||||
|
var quotient = Math.DivRem(dividend, divisor, out remainder);
|
||||||
|
if (remainder == 0)
|
||||||
|
return quotient;
|
||||||
|
return quotient + (Math.Sign(dividend) == Math.Sign(divisor) ? 1 : -1);
|
||||||
|
}
|
||||||
|
|
||||||
public static string JoinWith<T>(this IEnumerable<T> ts, string j)
|
public static string JoinWith<T>(this IEnumerable<T> ts, string j)
|
||||||
{
|
{
|
||||||
return string.Join(j, ts);
|
return string.Join(j, ts);
|
||||||
|
|||||||
Reference in New Issue
Block a user