在C#中的数学模

编程入门 行业动态 更新时间:2024-10-26 08:33:32
本文介绍了在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#中的数学模

本文发布于:2023-10-24 08:56:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523502.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数学

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!