prePEP: Decimal data type

Batista, Facundo FBatista at
Tue Nov 4 18:46:26 CET 2003

John Roth wrote:

#- As I said in the response to Alex, division is the one place where
#- fixed decimal gets into trouble. To repeat what I said to him,
#- I'd eliminate the division operators completely, and replace them
#- with a div(dividend, divisor, [resultplaces], [roundingpolicy])
#- operator.

Don't like it.

Why can't I do a / b (being a and b decimals)? Sure there're answers, but
Decimal is a numeric type and I *want* to divide in the standard way.

And remember that the result places is the precision and the rounding policy
is defined in the context, so those always are being taken in consideration.

#- > >> When passing floating point to the constructor, what 
#- should happen?
#- > >>
#- > >>     j. ``Decimal(1.1) == Decimal('1.1')``
#- > >>     k. ``Decimal(1.1) ==
#- > >> Decimal('110000000000000008881784197001252...e-51')``
#- > >
#- > ...
#- > As I say, it's hard.
#- Not that hard. It's not at all difficult to find where the 
#- actual number
#- ends and where the fuzz begins. You can do it visually, and the
#- algorithms to do it are quite well known. That's how 
#- printing libraries
#- handle the issue, after all.

But If I *really* want my number to be
Decimal('110000000000000008881784197001252...e-51'), why can't I write
Decimal(1.1)? Why should I expect Decimal to be "rounding" it? 

Remember that I *know* that 1.1 is binary floating point, so I can predict
the result. It's not intuitive to a begginer, nut that's the way it is.

.	Facundo

More information about the Python-list mailing list