P
Paul Butler
Guest
My understanding of 1076-2002 is that the value "integer'high + 1" is out of
range for a variable of type integer. Modelsim PE 5.8b seems to implement
the integer type as a 2's complement 32 bit number so that (integer'high +
1) = integer'low. For most values of an integer variable D32,
integer'succ(D32) = D32 + 1. However, for at least one value,
integer'succ(D32) is out of range while D32+1 is integer'low.
Is Modelsim's behavior incorrect? How do other simulators behave?
Paul Butler
PS I claim that the following code should produce a fatal "out of range"
error. The code shows that, in Modelsim, adding two positive numbers can
produce a negative sum.
entity \Integer range demonstration\ is
end entity \Integer range demonstration\;
architecture \Test\ of \Integer range demonstration\ is
begin
\32 bit 2's complement\:
Process is
variable \Integer Variable\ : integer;
variable \Increment\, \Decrement\ : integer;
begin
\Integer Variable\ := integer'high;
\Increment\ := \Integer Variable\ + 1;
assert \Increment\ > \Integer Variable\
report "integer'high + 1 = " & integer'image(\Increment\);
\Integer Variable\ := integer'low;
\Decrement\ := \Integer Variable\ - 1;
assert \Decrement\ < \Integer Variable\
report "integer'low - 1 = " & integer'image(\Decrement\);
wait;
end process \32 bit 2's complement\;
end architecture \Test\;
range for a variable of type integer. Modelsim PE 5.8b seems to implement
the integer type as a 2's complement 32 bit number so that (integer'high +
1) = integer'low. For most values of an integer variable D32,
integer'succ(D32) = D32 + 1. However, for at least one value,
integer'succ(D32) is out of range while D32+1 is integer'low.
Is Modelsim's behavior incorrect? How do other simulators behave?
Paul Butler
PS I claim that the following code should produce a fatal "out of range"
error. The code shows that, in Modelsim, adding two positive numbers can
produce a negative sum.
entity \Integer range demonstration\ is
end entity \Integer range demonstration\;
architecture \Test\ of \Integer range demonstration\ is
begin
\32 bit 2's complement\:
Process is
variable \Integer Variable\ : integer;
variable \Increment\, \Decrement\ : integer;
begin
\Integer Variable\ := integer'high;
\Increment\ := \Integer Variable\ + 1;
assert \Increment\ > \Integer Variable\
report "integer'high + 1 = " & integer'image(\Increment\);
\Integer Variable\ := integer'low;
\Decrement\ := \Integer Variable\ - 1;
assert \Decrement\ < \Integer Variable\
report "integer'low - 1 = " & integer'image(\Decrement\);
wait;
end process \32 bit 2's complement\;
end architecture \Test\;