Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix bug in number_of_bits for integer'high

  • Loading branch information...
commit 294f821547c7405054f3adeb8c7d1e9cbb0ceaeb 1 parent 814a30d
@martinjthompson authored
Showing with 5 additions and 2 deletions.
  1. +5 −2 libv.vhd
View
7 libv.vhd
@@ -120,10 +120,12 @@ package body libv is
function number_of_bits (
value : positive)
return positive is
- variable bits : positive := 1;
+ variable bits : natural := 0;
+ variable val : natural := value;
begin
- while 2**bits <= value loop
+ while val > 0 loop
bits := bits + 1;
+ val := val / 2;
end loop;
return bits;
end function number_of_bits;
@@ -251,6 +253,7 @@ begin -- architecture test
assert_equal("number_of_bits", number_of_bits(8), 4);
assert_equal("number_of_bits", number_of_bits(200), 8);
assert_equal("number_of_bits", number_of_bits(1200), 11);
+ assert_equal("number_of_bits", number_of_bits(integer'high), 31);
assert_equal("str(int)", str(0), "0");
assert_equal("str(int)", str(10), "10");
Please sign in to comment.
Something went wrong with that request. Please try again.