Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Negative number rounding confusion

Reply
Thread Tools

Negative number rounding confusion

 
 
ShortCircuit ShortCircuit is offline
Junior Member
Join Date: Apr 2010
Posts: 6
 
      04-12-2010
Lately I have been doing some fractional binary calculations with signed binary numbers in the 2's complement format. I have a reasonable understanding of how to add, sub, multiply with these numbers etc. However I continue to get caught out by a 2's complement misunderstanding or by possible rounding confusion.

I am writing VHDL model to match a C algorithm, so I have benchmark of what results I should be getting from this C code. My VHDL model matches the expected C results except for when I get a negative result, which is always -1 off from where I expect it to be.

I am trying to implement the following equation:
X=(A-B)*C;
where A & B are integers represented in binary,
and C is a fractional binary number

Examples:
( 4 - ( -121 ) )*20.0928 = 2511.6
---> In modelSim I get a result of 2511 (Decimal), which is what I expected

( -1 - 68 )*5.9936 = -413.558
--> In VHDL I get -414, when I expected -413.

In VHDL I perform this calculation then shift right and resize the result inorder to get it into the correct width and with the correct binary point location.

Is this normal for the negative numbers to round down? I assumed the fractional part would just be disregarded. Has anyone else experienced this issue?

Thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Adding a positive number and a negative number MRAB Python 2 01-31-2009 02:41 AM
Adding a positive number and a negative number EK Python 0 01-30-2009 04:13 AM
Formatting a number without rounding Thor W Hammer ASP .Net 2 11-22-2005 06:51 PM
Small confusion about negative lookbehind david.karr@wamu.net Java 2 05-31-2005 03:58 AM
Negative setup and Negative hold prem_eda VHDL 5 10-11-2004 12:14 PM



Advertisments