本文介绍了在C#中的数学模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有在c#为一个数的数学模量的库函数 - 该我特别意味着一个负整数模的正整数应产生一个肯定的结果
Is there a library function in c# for the mathematical modulus of a number - by this I specifically mean that a negative integer modulo a positive integer should yield a positive result.
编辑,以提供一个例子:
edited to provide an example:
-5模3应该返回1
-5 modulo 3 should return 1
推荐答案尝试(A%b)* Math.Sign(一)
试试这个;它工作正常。
Try this; it works correctly.
static int MathMod(int a, int b) { return (Math.Abs(a * b) + a) % b; }更多推荐
在C#中的数学模
发布评论