Alternative to Decimal type

Ethan Furman ethan at stoneleaf.us
Wed Jun 11 10:39:43 EDT 2008


Frank Millman wrote:
> Thanks to all for the various replies. They have all helped me to
> refine my ideas on the subject. These are my latest thoughts.
> 
> Firstly, the Decimal type exists, it clearly works well, it is written
> by people much cleverer than me, so I would need a good reason not to
> use it. Speed could be a good reason, provided I am sure that any
> alternative is 100% accurate for my purposes.

[snip]

> For addition, subtraction, multiplication and division, the 'other'
> number can be any of 2, 3, or 4 above. The result is a new Number
> instance. The scale of the new instance is based on the following rule
> 
> For addition and subtraction . . .
> For multiplication . . . 
> For division . . .

Out of curiosity, what is the purpose of these numbers?  Do they 
represent money, measurements, or something else?  The reason I ask is 
way back in physics class (or maybe chemistry... it was way back :)  I 
was introduced to the idea of significant digits -- that idea being that 
a measured number is only accurate to a certain degree, and calculations 
using that number therefore could not be more accurate.  Sort of like a 
built-in error range.

I'm thinking of developing the class in the direction of maintaining the 
significant digits through calculations... mostly as I think it would be 
fun, and it also seems like a good test case to get me in the habit of 
unit testing.  I'll call it something besides Number, though.  :)

Is anybody aware of such a class already in existence?
--
Ethan



More information about the Python-list mailing list