首页 > 其他 > 详细

VHDL MOD和REM(转)

时间:2015-06-04 15:23:09      阅读:566      评论:0      收藏:0      [点我收藏+]

mod(取模)and rem(取余)

VHDL has mod and rem. They return the same value if both arguments are positive.

but, they produce different results for negative inputs:

5 mod 3 = 2

(-5) mod 3 = 1

5 mod (-3) = -1

(-5) mod (-3) = -2

for mod, the result has the same sign with the first argument.

whereas

5 rem 3 = 2

(-5) rem 3 = -2

5 rem (-3) = 2

(-5) rem (-3) = -2

for rem,the result has the same sign with the second argument.

A rem B = A - ( A / B ) * B --余数运算符 利用操作数A决定结果的正负号

 

取余运算(a REM b)的符号与a相同,其绝对值小于b的绝对值。

 

A mod B = A - B * N --取模运算符 利用操作数B决定结果的正负号

 

取模运算(a MOD b)的符号与b相同,其绝对值小于b的绝对值。

 

VHDL MOD和REM(转)

原文:http://www.cnblogs.com/zhumeng321/p/4551826.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!