Questions about negate a negative number

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

  1. fl

    fl Guest

    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,
    fl, Feb 20, 2014
    #1
    1. Advertising

  2. fl

    GaborSzakacs Guest

    fl wrote:
    > 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.

    --
    Gabor
    GaborSzakacs, Feb 20, 2014
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. prem_eda
    Replies:
    5
    Views:
    7,845
    Pieter Hulshoff
    Oct 11, 2004
  2. Rob Mitchell

    [Q] fast way to negate?

    Rob Mitchell, Dec 13, 2005, in forum: Java
    Replies:
    0
    Views:
    357
    Rob Mitchell
    Dec 13, 2005
  3. Replies:
    3
    Views:
    552
    Paul McGuire
    Jan 9, 2005
  4. EK
    Replies:
    0
    Views:
    314
  5. MRAB
    Replies:
    2
    Views:
    302
    John Machin
    Jan 31, 2009
Loading...

Share This Page