VHDL如何同时使用floor和log2

VHDL如何同时使用floor和log2,vhdl,floor,Vhdl,Floor,在下面的代码中,如果N等于127或128,我总是得到BitLength=7和BitLength2=6。有人能解释一下吗 constant N : integer := 128; constant N_LOG2 : real := log2(real(N)); signal BitLength : integer := integer(N_LOG2); signal BitLength2 : integer := integer(floor(N_LOG2)); 我希望BitLength始终等于B

在下面的代码中,如果N等于127或128,我总是得到BitLength=7和BitLength2=6。有人能解释一下吗

constant N : integer := 128;
constant N_LOG2 : real := log2(real(N));
signal BitLength : integer := integer(N_LOG2);
signal BitLength2 : integer := integer(floor(N_LOG2));
我希望BitLength始终等于BitLength 2:

  • 对于N=127,它们应等于6
  • 对于N=128,它们应该等于7

整数(一些实数)
总是四舍五入到最近的整数,因此它将6.9887四舍五入到7。所以当N=127时,
BitLenth
=7和
bitlenth2
=6。当N=128时,它们都应该是7。7的浮点数表示法可能有一些奇怪的地方,当它落地时。@我不知道整数舍入到最接近的值。我以为它只需要整数部分。我理解N=127的情况。对于N=128,如何解释BitLength2=6上的“怪癖”?这不是一只虫子吗?我怎样才能避免这种情况?