OpenCores
URL https://opencores.org/ocsvn/special_functions_unit/special_functions_unit/trunk

Subversion Repositories special_functions_unit

[/] [special_functions_unit/] [Open_source_SFU/] [log2_pkg.vhd] - Rev 4

Compare with Previous | Blame | View Log

-- f_log2 calcula el logaritmo natural de dos de un numero,
-- retorna entero: f_log2(23) = 5, f_log2(16) = 4, f_log2(17)=5 
library ieee;
use ieee.std_logic_1164.all;
 
 
package log2_pkg is
 
	function f_log2 (x : positive) return natural;
 
end package;
 
 
package body log2_pkg is	
 
	function f_log2 (x : positive) return natural is
		variable i : natural:=0;
	begin
		i := 0;  
		while (2**i < x) and i < 31 loop
				i := i + 1;
		end loop;
		return i;
	end function;
 
end package body;

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.