# [Tutor] uncertainty pre-release and new 'round' PEP suggestion

Christopher Smith csmith@blakeschool.org
Wed, 29 Aug 2001 17:50:13 -0500

```OK, here's a binhex of a sit compression of the class which
works with numbers and their uncertainty.  (Sorry, no web
site that I can send it to yet.)

I'm still not exactly sure what the best arrangement of
the math functions is:

1) both method and function syntax allowed for as pat present

2) just function syntax where all the definitions of methods
would have to be moved up into the functions.  One pro for
this is less likelihood for user error when dooing something
like a**b.log()--does the user know if this does (a**b).log()
or a**(b.log())?  The function syntax removes one level of
user error.

I'm having difficulty figuring out how to use coerce and
float successfully.  Bassically I would like to handle
addition of regular numberics and the PHYS class (formerly
called uncertain, but I haven't finalized on a name yet).
If I define coerce then I get a complaint about not having
__float__defined.  And if I put in an additional float
definition then I get an infinite loop.  I just don't have
a lot of time right now to solve this problem...if anyone
hsa some suggestions I could use the help.

When this is done I think it would be nice to add to
something like the SCIENTIFIC package.  Any other ideas?

Also, I have a suggestion for a PEP.  In addition to
ROUND with a +/- argument, allow for a decimal argument
which would round x to the dth digit after the first one.
Often in science I just want the first 3 digits wherever
they occur.  Here is how the function would behave:

from math import floor,log10
def Round(x,n):
d=n%1
if d==0:
return round(x,n)
else:
# going to treat everything after the decimal like an integer
d=str(d)
d=int(d[d.find('.')+1:])
return round(x,d-1-int(floor(log10(abs(x)))))

x=1.23456
print Round(x,2)        #1.23
print Round(x,0)        #1.0
print Round(x,.2)       #1.2
print Round(10*x,-1)    #10.0
print Round(10*x,.2)    #12.0
print Round(1000*x,.2)  #1200.0

Any comments on this for a PEP?

/c

(This file must be converted with BinHex 4.0)
:\$A"SHA-ZF(NZFfPd,M%!8dP8090*9#%!N!33r`#3"1+68h4eCQC*G#!SBbNa16N
h,6%j16JJ3@aKC'4TEL"6HA0dC@ec,#"*EQ-Z,#"SG(4`1Lm[Gj!\$,Q&XB@4ND@j
cHA-ZBfpY,e0dG@CQ5A3[\$3SD!!83!!!3r`#3!h)!!3#3!h)cY3fPT9*PFf9bGQ9
NTD8!TC!%!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