Thus spake Wolfgang Sourdeau: > La plume légère, à Tue, Sep 26, 2000 at 11:21:03AM -0400, heure d'inpiration, > Havoc Pennington écrivait en ces mots: > > This is just how floating point works; you lose precision. Floating > > point can't actually represent the exact number you asked for, it > > picks the closest one. > > Yeah, I realize that. Although I can understand that fp numbers > can't be counted on for precision, I don't see why it's not possible > to obtain 1 + 0.001 = 1.001 instead of 1.000999993943 (or sth like this). > If I recall, the way floats are stored is in some kind of scientific > representation, that is 0.001=1E-3, isn't it? > > > > > Havoc > > Wolfgang AFAIK, floats in C are stored as binary expansions with exponent, not decimal, which accounts for the weird behaviour of decimal floats. e.g., 1/10 decimal is prolly stored as something like (binary) 0.000110010...etc. Where precision actually matters more than speed, there are assorted packages to get arbitrary/fixed precision numbers. -- -nils Public key: http://www.fas.harvard.edu/~nbarth/pub-key.txt
Attachment:
pgpxVhYX20Oh8.pgp
Description: PGP signature