# Re: [vhdl-200x] numeric_std division problem

From: David Bishop <dbishop@eda.org>
Date: Mon Aug 11 2014 - 17:39:11 PDT
```On 8/11/2014 4:44 PM, Graham, Paul wrote:
>
> I've hit a problem with the definition of signed division in
> numeric_std.  With this function:
>
>   function "/" (L: SIGNED; R: INTEGER) return SIGNED is
>
> if L is "100" (that is, -4), and R is 4, then the function returns,
> not -1, but 0.  This is because:
>
>     constant R_LENGTH: NATURAL := MAX(L'LENGTH, SIGNED_NUM_BITS(R));
>
>     ...
>
>     if (R_LENGTH > L'LENGTH) then
>
>       QUOT := (others => '0');
>
>       return RESIZE(QUOT, L'LENGTH);
>
>     end if;
>
> The signed_num_bits function says that to represent 4 as a signed
> value requires 4 bits.  This is correct.  Because R's bit
> representation is larger than  L's bit represented the function
> returns zero.
>
> The result of (-4) / 4 should be -1, not 0.  Isn't this a bug in in
> numeric_std?
>
>
In the signed math packages the result is the size of the "left" argument.

SO:   if you give it "100" ( = -4) and 4 (integer = 0100)
First the 4 is converted into a signed vector, but this causes an
overflow because +4 won't fit into a 3 bit signed number.   You need one
more bit here to make this work.

This function has been there since numeric_std first came out.   The
fixed point packages behave much better in overflow/saturation issues.

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
```
Received on Mon Aug 11 17:39:24 2014

This archive was generated by hypermail 2.1.8 : Mon Aug 11 2014 - 17:40:06 PDT