Modulo

模运算在计算中用于求解除法后的余数,例如5mod2等于1,因为5除以2的余数是1。通常在整数之间进行,但在现代计算系统中也可用于其他类型的数值。当涉及负数时,定义可能因编程语言而异,且有特定的处理方式。模运算在编程和数论中有广泛应用。
摘要由CSDN通过智能技术生成

In computing, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another (called the modulus of the operation).

Given two positive numbers a and n, a modulo n (often abbreviated as a mod n) is the remainder of the Euclidean division of a by n, where a is the dividend and n is the divisor.[1]

For example, the expression “5 mod 2” would evaluate to 1, because 5 divided by 2 has a quotient of 2 and a remainder of 1, while “9 mod 3” would evaluate to 0, because 9 divided by 3 has a quotient of 3 and a remainder of 0; there is nothing to subtract from 9 after multiplying 3 times 3.

Although typically performed with a and n both being integers, many computing systems now allow other types of numeric operands. The range of values for an integer modulo operation of n is 0 to n − 1 inclusive (a mod 1 is always 0; a mod 0 is undefined, possibly resulting in a division by zero error in some programming languages). See Modular arithmetic for an older and related convention applied in number theory.

When exactly one of a or n is negative, the naive definition breaks down, and programming languages differ in how these values are defined.

Contents

Variants of the definition
Notation
Common pitfalls
Performance issues
Properties (identities)
In programming languages
Generalizations

Modulo with offset
Implementing other modulo definitions using truncation
See also

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值