Aritmetica de Ponto Flutuante

De CoteiaWiki
Revisão de 11h57min de 17 de março de 2015 por Moacir (discussão | contribs) (Criou página com ''''Porque o número float/double apresenta um erro de precisão?''' No padrão de ponto flutuante (usado para armazenar em binário os tipos float e double), a parte fracion...')
(dif) ← Edição anterior | Revisão atual (dif) | Versão posterior → (dif)

Porque o número float/double apresenta um erro de precisão?

No padrão de ponto flutuante (usado para armazenar em binário os tipos float e double), a parte fracionária do número (ou seja, aquela depois da vírgula) é obtida pela soma de potências de 2 sucessivas. Por exemplo

.1011 = 1/2 + 0/4 + 1/8 + 1/16

Assim, temos que "Squeezing infinitely many real numbers into a finite number of bits requires an approximate representation. Although there are infinitely many integers, in most programs the result of integer computations can be stored in 32 bits. In contrast, given any fixed number of bits, most calculations with real numbers will produce quantities that cannot be exactly represented using that many bits. Therefore the result of a floating-point calculation must often be rounded in order to fit back into its finite representation. This rounding error is the characteristic feature of floating-point computation." Veja mais em: external link: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html