Short-circuit Logic

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu May 30 01:20:42 EDT 2013


On Wed, 29 May 2013 20:23:00 -0400, Dave Angel wrote:

> Even in a pure decimal system of (say)
> 40 digits, I could type in a 42 digit number and it would get quantized.
>   So just because two 42 digit numbers are different doesn't imply that
> the 40 digit internal format would be.

Correct, and we can demonstrate it using Python:

py> from decimal import *
py> getcontext().prec = 3
py> a = +Decimal('1.0000')
py> b = +Decimal('1.0009')
py> a == b
True


(By default, the Decimal constructor does not honour the current 
precision. To force it to do so, use the unary + operator.)
    



-- 
Steven



More information about the Python-list mailing list