取模运算在数学定义与机器理解的区别
2017-11-19 00:11
267 查看
纪念我c语言第一次课堂作业被坑
取模运算(“MOD”)
数学定义:
谷歌到《Concrete Mathematics》上的一段,原文:
The quotient of n divided by m is [n/m],when m and n are positive
integers. It’s handy to have a simple notation also for the remainder
of this division, and we call it ‘n mod m’, The basic formula
n = m[n/m]+ n mod m
//NOTE:”m[n/m]” is quotient, “n mod m” is remainder
tells us that we can express n mod m as n-m[n/m] .We can generalize this
to megative integers, and in fact to arbitrary real numbers:
1.数学上:[x/y]为x/y的最小下界
举个栗子:
5 mod 2=5 - 2 * [5/2]
=5 - 2 * [2.5]
=5 - 2 * 2
=1
2.机器上:[x/y]=(x/y)其实就是取余
再举个栗子:
5 mod 2 = 5 - 2 * [5/2]
=5 - 2 * (5/2)
=5 - 2 * (2)
=5 - 2 * 2
=
取模运算(“MOD”)
数学定义:
谷歌到《Concrete Mathematics》上的一段,原文:
摘自P82:
3.4 ‘MOD’: THE BINARY OPERATIONThe quotient of n divided by m is [n/m],when m and n are positive
integers. It’s handy to have a simple notation also for the remainder
of this division, and we call it ‘n mod m’, The basic formula
n = m[n/m]+ n mod m
//NOTE:”m[n/m]” is quotient, “n mod m” is remainder
tells us that we can express n mod m as n-m[n/m] .We can generalize this
to megative integers, and in fact to arbitrary real numbers:
x mod y = x - y[x/y], for y!=0.
在这里的余数(Remainder)其实就是取模(mod):x mod y=x % y=x-y(x/y),for y!=0.
在概念上数和机器的理解是相同的,然鹅……机器在实现上确是与数学有差异。1.数学上:[x/y]为x/y的最小下界
举个栗子:
5 mod 2=5 - 2 * [5/2]
=5 - 2 * [2.5]
=5 - 2 * 2
=1
2.机器上:[x/y]=(x/y)其实就是取余
再举个栗子:
5 mod 2 = 5 - 2 * [5/2]
=5 - 2 * (5/2)
=5 - 2 * (2)
=5 - 2 * 2
=
总结:so……以后在用代码实现时要千万记住:mod 是 % 是 取模 取模 取模!
公式:x mod y = x % y = x - y(x/y),for y!=0
相关文章推荐
- 预习(二)strlen sizeof staic extern 的定义理解与区别
- 声明和定义的区别(深入理解)
- C#二维数组的定义,初始化(重在理解两者的区别)
- 【离散数学】单射、满射和双射的定义、区别
- 【机器学习】1:机器学习定义、机器学习与数据建模、分析的区别
- 机器学习中的数学(1)——怎样形象的理解卷积
- 定义、公理、定理、推论、命题和引理的区别
- 怎样理解阻塞非阻塞与同步异步的区别?
- PCA及白化的数学理解
- C#中的虚方法,抽象类,重写,隐藏,重载的区别与理解
- 深入理解ob_flush和flush的区别
- 集群、网格、云 定义及区别
- 数学之路(机器学习实践指南)-文本挖掘与NLP(6)
- 一个例子叫你理解缓冲输入与非缓冲输入,以及流的概念:论read与fget open与fopen的区别
- String 定义对象的区别(堆与栈的不同之处)
- JS 判断 取 当前系统类型 可用来定义某些WIN7系统和XP系统下字体区别
- 个人理解‘==’和equals()的区别
- IOS 成员变量,全局变量,局部变量定义,static与extern的区别
- 关于Apache/Tomcat/JBOSS/Neginx/lighttpd/Jetty等一些常见服务器的区别比较和理解
- DDL、DML和DCL的区别与理解