VHDL MOD和REM(轉)

mod(取模)and rem(取餘) spa

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

but, they produce different results for negative inputs: input

5 mod 3 = 2 it

(-5) mod 3 = 1 di

5 mod (-3) = -1 co

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

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

whereas return

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的絕對值。

相關文章
相關標籤/搜索