Questions about negate a negative number

Discussion in 'VHDL' started by fl, Feb 20, 2014.

  1. fl

    fl Guest


    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?

    fl, Feb 20, 2014
    1. Advertisements

  2. fl

    GaborSzakacs Guest

    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.
    GaborSzakacs, Feb 20, 2014
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.