Questions about negate a negative number

F

fl

Hi,

I am new to VHDL. My project is about designing a division lookup table forsigned number entries. In order to use less resources, I want to implementthe table only for positive entries. "The sign of the division result can be evaluated by an XOR gate." If the result sign is negative, it may need to negate a division operand. For example, if the signed number is 16-bit, Ican negate -32700 by bit-wise not the bits and add 1. Is this method right? Or do you have a better and simple method?

Second, how to deal with -32768, because the maximum positive number is 32767.

I have read VHDL data type conversion of signed and unsigned. I do not findthey are useful in my problem yet. signed, unsigned are only a number interpretation?


Thanks,
 
G

GaborSzakacs

fl said:
Hi,

I am new to VHDL. My project is about designing a division lookup table for signed number entries. In order to use less resources, I want to implement the table only for positive entries. "The sign of the division result can be evaluated by an XOR gate." If the result sign is negative, it may need to negate a division operand. For example, if the signed number is 16-bit, I can negate -32700 by bit-wise not the bits and add 1. Is this method right? Or do you have a better and simple method?

Second, how to deal with -32768, because the maximum positive number is 32767.

I have read VHDL data type conversion of signed and unsigned. I do not find they are useful in my problem yet. signed, unsigned are only a number interpretation?


Thanks,

Dealing with cases like -32768 is usually a large portion of the design
process. You need to decide how you want to handle it. For example,
you could say it represents an "overflow error" and cause an exception
in the process. You could also say 32767 is close enough to 32768 for
your purposes and then you just need to "saturate" to the maximum number
that can be expressed in the given number of bits.

One way to deal with situations like this is to use an intermediate
format that can hold any possible answer, and then check the result
to see if it will fit in the output size. In the case of negating
a 16-bit number, you could use 17 bits when doing the negation, and
then clip to 32767 if the result is greater than 32767.

On the other hand, when doing a table you might just decide not to have
table entries that could cause an overflow, for example using -32767
in the table value instead of -32768.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top