On Wed, Dec 21, 2011 at 12:24:09PM -0800, Michael R wrote: > > > I was reminded of something this morning.?? Perhaps you will enjoy > the puzzle. > > ?mikeraz@hive:~> perl -e 'my $x = > (.0425 * > 2) + .0025; print $x - (.0425 * 2) - .0025, $/;' > > ?2.16840434497101e-18 > ?mikeraz@hive:~> > > > > Silly me would expect something like 0 to be printed. Why the > 2.16840434497101e-18? (OK, round it off and you have 0, but ....)
That's floating point for you, and most traditional languages use that by default. If you want exact calculations, you have to use a library specifically designed for them, or use a language which does exact calculations by default. tim _______________________________________________ PLUG mailing list [email protected] http://lists.pdxlinux.org/mailman/listinfo/plug
