Spartan-3A a AN -signed/unsigned matematika

Marek Peca marek na duch.cz
Čtvrtek Leden 2 00:33:37 CET 2014


>> -----Original Message-----
>> From: Hw-list [mailto:hw-list-bounces at list.hw.cz] On Behalf Of David
>> Belohrad
>> Sent: 30. prosince 2013 19:03
>> To: HW-news
>> Subject: Re: Spartan-3A a AN -signed/unsigned matematika
>> 
>> 
>> Jenom tak na okraj. Pouzivam tuhle funkci:
>>
>>      function bits_to_fit (N : natural) return natural is
>>          variable vIntermediatexD : natural;
>>          variable vBitCountxD     : natural;
>>      begin
>>          vIntermediatexD := N;
>>          vBitCountxD     := 0;
>>          loop
>>              exit when vIntermediatexD = 0;
>>              vIntermediatexD := vIntermediatexD / 2;
>>              vBitCountxD     := vBitCountxD + 1;
>>          end loop;
>>
>>          if vBitCountxD = 0 then
>>              return 1;
>>          end if;
>>
>>          return vBitCountxD;
>>      end;
>> 
>> 
>> Date tomu cislo, a ono vam to vypocita, kolik potrebujete bitu. (..)

Ano, toto je velmi uzitecna konstrukce. Pouzivam hojne. Akorat v tomto o 
neco poetictejsim rekurentnim vyjadreni ;-):

function ceil_log2(n: natural) return natural is
begin
   if n <= 1 then
     return 0;
   else
     if n mod 2 = 0 then
       return 1 + ceil_log2(n/2);
     else
       return 1 + ceil_log2((n+1)/2);
     end if;
   end if;
end function ceil_log2;

Dale se hodi i nasledujici:

function ceil_div(a: integer; b: integer) return integer is
begin
   return (a+b-1)/b;
end function ceil_div;


ZdraviM.P.


Další informace o konferenci Hw-list