La rappresentazione dei numeri interi: i numeri fixed point Numeri ...
La rappresentazione dei numeri interi: i numeri fixed point Numeri ...
La rappresentazione dei numeri interi: i numeri fixed point Numeri ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>La</strong> <strong>rappresentazione</strong> <strong>dei</strong> <strong>numeri</strong><br />
<strong>interi</strong>: i <strong>numeri</strong> <strong>fixed</strong> <strong>point</strong><br />
<strong>Numeri</strong> <strong>fixed</strong> <strong>point</strong><br />
Fissare<br />
– <strong>La</strong> base<br />
– Il numero di cifre a disposizione<br />
per il valore assoluto<br />
1 per il segno<br />
Indichiamo con la <strong>rappresentazione</strong><br />
<strong>fixed</strong> <strong>point</strong> di un intero
Rappresentazione <strong>fixed</strong> <strong>point</strong> di un<br />
intero positivo N<br />
A seconda del numero di cifre della<br />
<strong>rappresentazione</strong> di N in base si ha<br />
Esempio: <strong>rappresentazione</strong> <strong>fixed</strong><br />
<strong>point</strong> di 1235 in base 2 con 16 cifre
Se t < p allora fi(N) è il resto della<br />
divisione di N per<br />
Esempio<br />
Il più grande intero positivo<br />
rappresentabile esattamente<br />
Sono rappresentabili esattamente solo gli<br />
<strong>interi</strong> positivi compresi nell’intervallo
Si richiama la formula<br />
Che si ricava da<br />
Rappresentazione degli <strong>interi</strong><br />
negativi<br />
<strong>La</strong>voriamo in base 2.<br />
Complemento a 2 in t+1 cifre<br />
Una regola pratica per ottenere il<br />
complemento a 2 è la seguente:<br />
Prendere<br />
Scambiare 1 con 0 e 0 con 1<br />
Aggiungere 1.
Esempio: <strong>rappresentazione</strong> <strong>fixed</strong> <strong>point</strong><br />
di –1235 in base 2 con 16 cifre<br />
toggle<br />
aggiungi 1<br />
Il primo bit è sempre uguale a 1!
Il più piccolo intero negativo<br />
rappresentabile su t+1 cifre in base 2<br />
Infatti si ha<br />
Per valori negativi più piccoli si incorre nell’underflow<br />
intero<br />
L’insieme degli <strong>interi</strong><br />
rappresentabili esattamente in<br />
<strong>fixed</strong> <strong>point</strong>, base 2, t+1 cifre<br />
È costituito dagli <strong>interi</strong> contenuti<br />
nell’intervallo<br />
In generale, se la base è
Esempi<br />
Insieme <strong>dei</strong> <strong>numeri</strong> <strong>fixed</strong> <strong>point</strong>,<br />
base 2, 4 cifre
Esercizi<br />
Aritmetica <strong>fixed</strong> <strong>point</strong>: somma
Aritmetica <strong>fixed</strong> <strong>point</strong>: sottrazione<br />
Programma per calcolare il numero<br />
di cifre e il massimo intero<br />
#include <br />
#include <br />
main()<br />
{<br />
int num;<br />
double it,pr;<br />
num=1;<br />
while(num>=0) ++ num;<br />
-- num;<br />
pr=num;<br />
it=log10(pr+1)/log10(2);<br />
printf("max int rappresentabile=\%d cifre=\%lf",num,it+1);<br />
num=-1;<br />
while(num
Artimetica <strong>fixed</strong> <strong>point</strong>: prodotto<br />
Siccome il prodotto di due <strong>numeri</strong> a t+1 cifre<br />
può essere a 2(t+1) cifre, si può incorrere<br />
nell’ overflow intero.<br />
Si esegue con addizioni e scorrimenti a<br />
destra.<br />
Aritmetica <strong>fixed</strong> <strong>point</strong>: quoziente<br />
Sottrazioni e scorrimenti a sinistra.
L’aritmetica <strong>fixed</strong> <strong>point</strong> è esatta<br />
purchè si rimanga nell’intervallo di<br />
<strong>rappresentazione</strong>, cioè a meno di<br />
overflow