除以零后的余数 [英] Remainder after division by zero

查看:60
本文介绍了除以零后的余数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道数学中不允许用零除,但是我可以用零取模,应该得到什么答案?

I know that division by zero is not allowed in math, but can I use modulo by zero and what answer should I get?

例如

10%0 = ?
5%0 = ?

推荐答案

标准将其定义为未定义".

The standard defines it as "undefined".

在几乎所有处理器中,模都是由与除法相同的功能执行的.在现代的大型处理器中,它是一条指令(例如x86).通常,此指令在被零除时将导致陷阱,并且无论代码是打算使用模"部分还是商"部分,这都适用.

In nearly all processors, the modulo is performed by the same functionality as divide. In modern larger processors, it's an instruction (x86 for example). Most often, this instruction will cause a trap when dividing by zero, and this applies whether the code is "intending to use the modulo" or "quotient" part.

它是未定义的,因此处理器和编译器可以自由实现自己喜欢的功能-例如如果处理器只是返回任何输入作为输入,这也是允许的,或者如果它导致整个操作系统崩溃,那么按照标准,这也是很好的".

It is undefined so that processors and compilers have the freedom to implement what they fancy - e.g. if the processor just returns whatever came in as the input, that's also allowed, or if it causes the entire OS to crash, that's "fine" too by the standard.

总而言之,零模与除零一样差.

In summary, modulo of zero is just as bad as divide by zero.

(请注意,通常情况下,浮点除以零不会捕获(默认情况下),并且会生成无穷大值,除非除的值也是零,在这种情况下,您会得到非数字")

(Note that typically, floating point divide by zero does NOT trap [by default], and produces a infinity value, except if the value divided is also zero, in which case you get "not a number")

这篇关于除以零后的余数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆