On Tue, 20 Apr 2010 09:58:06 -0700 (PDT) Lowell Tackett <lowelltack...@yahoo.com> wrote:
> I'm running headlong into the dilemma of binary math representation, with > game-ending consequences, e.g.: > > >>> 0.15 > 0.14999999999999999 > [...] > The last line should be zero, and needs to be for me to continue this > algorithm. > > Any of Python's help-aids that I apply to sort things out, such as formatting > (%), or modules like "decimal" do nothing more than "powder up" the display > for visual consumption (turning it into a string). The underlying float > value remains "corrupted", You are wrong: >>> from decimal import Decimal >>> s = "0.15" >>> Decimal(s) == float(s) This shows, maybe weirdly, that the decimal version != 0.14999999999999999 --since it is actually equal to 0.15. Decimals are *not* internally represented as binary values, but instead with groups of bits each coding a *decimal* digit; this is precisely the point. Else why do you think developpers would cope with such a problem? Denis ________________________________ vit esse estrany ☣ spir.wikidot.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor