# [Tutor] class uncertainty

**Roeland Rengelink
**
r.b.rigilink@chello.nl

*Tue, 28 Aug 2001 10:30:41 +0200*

Roeland Rengelink wrote:
>*
*>* Christopher Smith wrote:
*>* >
*>* > I've created a class which keeps track of the uncertainty in a number and
*>* > subsequent calculations performed with that number. It works like this:
*
[snip]
>* >
*>* > def log(x):
*>* > if type(x)==<the type of my class>:
*>* > return uncertain.log(x)
*>* > return math.log(x)
*>* >
*>* > I would prefer the latter so the operation is as seamless as possible.
*>* > That's where I need the advise, though.
*>* >
*>*
*>* I think this is a good solution.
*>*
*
Where I was assuming you meant something like:
def log(x):
if isinstance(x, uncertain):
return x.log()
else:
return math.log(x)
with
class uncertain:
...
def log(self):
...return uncertain log...
So that module uncertain provides
- a log function that can take both exact and uncertain numbers as
argument
- an uncertain class that knows how to do a log of an uncertain number.
Hope this helps,
Roeland
--
r.b.rigilink@chello.nl
"Half of what I say is nonsense. Unfortunately I don't know which half"