Skip to content

Instantly share code, notes, and snippets.

@jfhbrook
Created April 9, 2010 00:49
Show Gist options
  • Save jfhbrook/360737 to your computer and use it in GitHub Desktop.
Save jfhbrook/360737 to your computer and use it in GitHub Desktop.
a long time ago, I was gonna try doing this for matlab. This looks easier. :S
"""
A sketch for an idea I've had since forever regarding significance arithmetic.
http://en.wikipedia.org/wiki/Significance_arithmetic
Yeah, that annoying shit you did in chemistry class and hoped never to see again.
With this, maybe you can?
"""
class significants(number):
# note: not actually sure how to do some of these things
def __init__:
# TODO: Be able to specify number of significant figures optionally
self.number=number
# find (sf, 10^x)
# 1) Find decimal place, if any.
if !decimal_place:
# find first_n_nonzero
# find zeros_after
# self.sf=first_n_nonzero
else:
# find num_dec_digits
# find length_of_number
#self.sf=length_of_number
# note: Use banker's rounding
def __mult__(self,other):
sf_out=min(self.sf,other.sf)
def __add__(self,other):
if self.sd-self.ten2the > other.sd-other.ten2the:
sf_out = self.sd
else:
sf_out = other.sd
if __name__ == "__main__":
#tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment