本文主要是介绍vhdl中mod与rem的区别,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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 mod B = A - B * N --取模运算符 利用操作数B决定结果的正负号
这篇关于vhdl中mod与rem的区别的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!