On Mon, 22 Mar 2010 08:47:53 am Greg Ewing wrote: > Nick Coghlan wrote: > > That's fine - binary floats *are* surprising. That's why Decimal > > exists in the first place. > > This argument could equally well be used the other way -- > someone using Decimal is doing so precisely because they > *don't* want to be surprised, in which case they would > probably prefer to get an exception.
Then they're in for a terrible, terrible disappointment. Rounding issues don't go away because you're using Decimal instead of float, and I can't imagine anyone would like an exception in the following cases: >>> Decimal(1)/Decimal(3)*Decimal(3) == Decimal(1) False >>> Decimal(2).sqrt()**Decimal(2) == Decimal(2) False >>> Decimal(10**28)+Decimal(1)-Decimal(10**28) == Decimal(1) False Rounding isn't the only surprise: >>> x = Decimal("NAN"); x == x False Decimals are floats, but using radix 10 instead of radix 2. -- Steven D'Aprano _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com