extend methods of decimal module

Mark H. Harris harrismh777 at gmail.com
Thu Feb 27 21:15:46 EST 2014


On Thursday, February 27, 2014 5:50:55 PM UTC-6, Oscar Benjamin wrote:

>  . . . Calling Decimal on a float performs an exact binary to
> decimal conversion. Your reasoning essentially assumes that every
> float should be interpreted as an approximate representation for a
> nearby decimal value. 

That is the whole point exactly.  Yes, the exact binary to decimal conversion for float is the problem precisely.  But my solution does not assume any such thing... because the decimal module is "advertised" to support what I'm doing.  In other words, decimal correctly builds from a string literal in any case; even intermediary values.  Well, the digits past 16 (for a double) aren't valid anyway... and the ones before that (when passed to decimal as a string) get correctly created as a decimal object.

But here is the other point...  I am not planning on passing *any* of these functions a float... my system that uses dmath uses strings only, or decimals.    str(Decimal)  works,  as does  Decimal(str()).   So, I'm not really interested in floats at all...  but,  and here's the big BUT, I'm expecting folks to use dmath.py from the console (as I plan to) and they are going to punch in *floats*.  why?  because its natural.

Its just easier to type D(2.78)  than Deciaml('2.78').

Neither here nor there....   but the frustration is the fact that  floats  are so 1982.  Know what I mean?  This is the 21st century, and you know what,  we have got to get past this:
>>> 
>>> Decimal(.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')
>>> 

In other words,  we need to move to a numeric system of computation (decimal is a good start) that does not keep track of real values as  IEEE floats.  Back in the day, that was ok... today, its unacceptable.

So, Krah has a really nice (and fast) module that will help at least the python community (and users) to move into the 21st century.   My hat is off to Stefan, that's for sure.

I am going to keep playing with this, and making the changes you have suggested...  I'll put the code back up there on code.google  and see if I can make the repository work like its supposed to..

Thanks again for your assistance, I really appreciate it, Oscar.




More information about the Python-list mailing list