Re: vhdl operators
It is common knowledge that when two numbers are divided (dividend and divisor) it gives rise to a quotient and remainder. Commonly, the integer part of the division result is taken as the quotient and the remainder is calculated as:
r = a – b*q
where r -> remainder, a -> dividend, b -> divisor, q -> quotient
However, in reality, there are two types of this ‘r’ values possible – the remainder and modulo. This stems from how the quotient is calculated. Actually, if real value is allowed for quotients, there should be no scope for remainder, i.e., remainder must be equal to 0. Quotient and remainder occur only when integer values are used. To obtain an integer quotient, the exact rational quotient can be rounded of in two ways:
1. The truncated division method: The exact rational quotient is rounded off towards zero, i.e., the integer part of the exact rational quotient is preserved and the fractional part discarded
2. The floored division method: The exact rational quotient is rounded downwards (floored) on the number scale
Refer
https://en.wikipedia.org/wiki/Modulo_operation for better understanding.
To understand better, visualize the numbers on a typical Y-axis: zero at center, positive numbers above zero and negative numbers below zero.
Consider two real numbers +3.817 and -3.817.
1. Truncated division method:
a. +3.817: Move towards zero. So, move downwards on Y-axis. First integer encountered is +3. Therefore, rounded result = +3
b. -3.817: Move towards zero. So, move upwards on Y-axis. First integer encountered is -3. Therefore, rounded result = -3
2. Floored division method:
a. +3.817: Floor the number. So, move downwards on Y-axis. First integer encountered is +3. Therefore, rounded result = +3
b. -3.817: Floor the number. So, move downwards on Y-axis. First integer encountered is -4. Therefore, rounded result = -4
Calculating the ‘r’ value using the quotient resulting from truncated division method gives remainder while calculating the ‘r’ value using the quotient resulting from floored division method gives modulo.
Dividend | Divisor | Exact rational quotient | Truncated division rounding | Remainder | Floored division rounding | Modulo |
+5 | +3 | +1.6667 | +1 | 5 – 3(1) = +2 | +1 | 5 – 3(1) = +2 |
+5 | -3 | -1.6667 | -1 | 5 – (-3)(-1) = +2 | -2 | 5 – (-3)(-2) = -1 |
-5 | +3 | -1.6667 | -1 | -5 – 3(-1) = -2 | -2 | -5 – 3(-2) = +1 |
-5 | -3 | +1.6667 | +1 | -5 – (-3)(+1) = -2 | +1 | -5 – (-3)(+1) = -2 |
hi
i have one doubt regarding VHDL MOD OPERATORS.
What is difference between mod and REM operators..
both are doing same operation .. i cant get..
anybody suggest the example for shifting operation..
for example i have two inputs a, b; i want to shift left two times for variable a.. the syntax is sll 2.. but my doubt is how i m going to confine that i shift only variable a not b.
plz reply
greetings.: