Nombres à virgule fixe
Package:
use ieee.fixed_pkg.all (n’est pas
supporté dans Quartus utilisé
dans les TPs)
Exemple d’addition
-nombres non signés
signal n1,n2 : ufixed(4 downto -3);
signal n3 : ufixed(5 downto -3);
begin
n1 <= to_ufixed (5.75,n1);
-- n1 = "00101110" = 5.75
n2 <= to_ufixed (6.5,n2);
-- n2 = "00110100" = 6.5
n3 <= n1+n2;
-- n3 = "001100010" = 12.25
-nombres signés:
signal s1,s2 : sfixed(4 downto -3);
signal s3 : sfixed(5 downto -3);
s1 <= to_sfixed (5.75,s1);
-- s1 = "00101110" = 5.75
s2 <= to_sfixed (-6.5,s2);
-- s2 = "11001100" = -6.5
s3 <= s1+s2;
-- s3 = "111111010" = -0.75
Exemple de soustration
-nombres non signés
n1 <= to_ufixed (5.75,n1);
n2 <= to_ufixed (6.5, n2);
n3 <= n2-n1; -- n3 = "000000110" = 0.75
-nombres signés
s1 <= to_sfixed (5.75,s1);
s2 <= to_sfixed (-6.5,s2);
s3 <= s2-s1;
-- s3 = "110011110" = -12.25