Skip to content

Corner case in ieee.numeric_std"/"[signed,integer]

For L="10000" (i.e. most negative number) and R=16, I would expect the mathematically correct answer to be -16 / 16 = -1, represented as "11111".

However, in ieee.numeric_std"/"[signed,integer] we have:

if (R_LENGTH > L'length) then
    QUOT := (others => '0');
    return RESIZE(QUOT, L'length);
end if;

But R_LENGTH works out to 6 bits, as "010000" is the smallest SIGNED that can represent +16. Therefore, we return "00000" which is not mathematically correct.

This corner case is similar to the (informative, not normative) position taken in G.3.3.1 of the LRM that "10000" / 1 does not signal an overflow.

Is this behavior a bug, or ought it to be added to G.3.3.1?

I discovered this while comparing results from the reference implementation to my own accelerated implementation, which returns "11111". Ought I to match the reference implementation, bugs and all?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information