[Python-ideas] isinstance(Decimal(), Real) -> False?

Steven D'Aprano steve at pearwood.info
Thu Aug 29 03:32:00 CEST 2013


On 28/08/13 20:30, Vernon D. Cole wrote:
> Darn right it should return False.  Given the principle of least surprise
> (and my prejudices built up over 40 years as a computer programmer) I would
> expect that decimal.Decimal data would be stored internally as some form of
> decimal data, and would store into a database as such.

"Some form of decimal data" -- so you're saying "Decimals are decimals". Well, that certainly clarifies matters :-)

Out of curiosity, those 40 years as a computer programmer, how much heavy-duty computational mathematics have you done? If you've spent 30 years writing business apps in COBOL and 10 years writing web apps in PHP, I wouldn't expect your prejudices about numeric computations to be trustworthy. (I know mine aren't, and I've spent years dabbling with numeric maths. The only reason I'm not surprised by computational mathematics is because I've learned not to trust my assumptions.)


> It would be
> expected to be in a fixed point format.

Decimal is a floating point format:

http://docs.python.org/2/library/decimal.html

so if you are assuming that Decimal is a fixed point number, your prejudices are wrong.

(Although I think the claims about exactness are misleading. There are plenty of numbers which cannot be represented exactly as decimals, just as they cannot be represented exactly as binary floats. 1/3 is the obvious example. Both float and Decimal suffer from the same inexactness issues, it's just that they sometimes suffer from them for different values.)


> Real, on the other hand, I would
> expect to be stored as an IEEE double precision floating point number, or
> something like that.
>    I don't care whether a fixed point decimal number might be defined by a
> mathematician as "real" -- I care whether it can be processed by an FPU,
> and whether it will loose precision in large financial calculations.

Membership of number.Real has little to do with what mathematicians consider real numbers. No floating point or fixed point implementation obeys the rules of real number arithmetic. But it's the traditional name, I expect due to the precedent set by Fortran.


-- 
Steven


More information about the Python-ideas mailing list