Thomas wrote...
> Jerry Park wrote:
> > Thomas wrote:
> >
> >> shouldn't the result after adding 0.03 to 0.27 be 0.3 ???
> >
> > No. Floating point arithmetic doesn't work that way. A fraction which
> > may be finite in one base may be a 'repeating decimal' in another
base.
> > Conversion from base 10 to base 2 and back to base 10 can result in
that
> > type of conversion error.
>
> I see....and I thought my computer is too dumb to count ;)
> It's not really a problem, I was just curious. But thanks for the info!
Welllll.... It *IS* a problem, but it's a problem that's built into the
methods most programming languages use to handle floating point numbers.
As such, most experienced programmers (who use such languages, anyway)
have bounced off it at least once, and know how to deal with it when they
run into it again.
Unless you want (or need) to go completely overboard and convert
everything in sight to/from integers in order to perform any arithmetic,
it's far easier to use some kind of method (e.g. rounding, like Jerry
mentioned upthread) to iron out the kinks afterwards.
A related problem is that of doing equality comparisons between
floating-point variables/numbers. YOU may think they're equal, but the
computer knows damn well that the numbers being compared are actually
0.30000000000 and 0.30000000001, which, as any right-thinking CPU knows,
are completely different numbers.
--
gav, anthropomorphising far too much.
Playing: Deus Ex; TFC1.5; Just Read: Yes, School's Out, Michael
Sheard; The League Of Extraordinary Gentlemen, Alan Moore et al.;
Guilty Pleasures, Laurell Hamilton;