Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What is difference between mod and REM operators?

Status
Not open for further replies.

mohan_ece

Newbie level 6
Joined
Jan 11, 2010
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,356
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.:
 

Re: vhdl operators

Hi,

Mod and REM operations are not the same...

Modulus issupports the result of integer division.
6 mod 4 : 2
6 mod -4 : -2
-6 mod 4 : 2

The remainder operation yields the remainder of integer division. It is defined for integer operands only and and the result is integer as well..
6 rem 4 : 2
6 rem -4 : 2
-6 rem 4 : -2

For shifting,
An input which you would like to shift must be bit_vector data type.. You can't use anything else...
And the syntax is : a(bit_vector) srl, sll, ror c(integer) value....
a ror c;

Ilgaz
 

Re: vhdl operators

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

this is wrong syntax you are using for shift operator..the actual syntax is..
syntax of shift operators are:

<left operand><operator><right operand>

left operand must be of type bit_vector only

right operand must be of type integer only

for eg....

a sll 2;
b srl 3;


greetings.:[/QUOTE priyanka priyadarshni]
 

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.
DividendDivisorExact rational quotientTruncated division roundingRemainderFloored division roundingModulo
+5+3+1.6667+15 – 3(1) = +2+15 – 3(1) = +2
+5-3-1.6667-15 – (-3)(-1) = +2-25 – (-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.:
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top