Measure class, precision, significant digits, and divmod()



Hey all.

My thanks to all who have responded so far with my other questions. It is much appreciated.

Some background on what I'm doing (a good explanation can be found at http://www.hazelwood.k12.mo.us/~grichert/sciweb/phys8.htm): When measuring, there is some uncertainty as to the *exact* value; so, when doing calculations with these measured numbers, one should not present an answer that seems more accurate than the source. For addition and subtraction this means the final answer cannot be more precise than the least precise input: 5.0 + 21.23 = 26.2 (first number only measured to the tenths, so answer only good to the tenths); for multiplication and division this means the answer cannot have more significant digits than the input with the fewest significant digits: 231 * 0.25 = 58 (0.25 only has two significant digits, so answer only has two significant digits). Important point -- counting is not subject to precision error.

As I have mentioned before, I am making this Measure class for two reasons: experience with unit testing, I like playing with numbers, I am unaware of anything like this having yet been done (okay, three reasons ;).

So far, I have the init, add, sub, mul, div, cmp, neg, pos, and abs done, and I'm ready to tackle floordiv, mod, and divmod... okay, maybe 'ready' is too strong a word -- one of the obstacle's I'm facing is that I, myself, don't have any real use for this class, so I'm stuck on deciding how floordiv, mod, and divmod should function. As mentioned above, counting is precise... so should divmod (a // b, a % b), which returns the count of times b goes into a, and the remainder, be an exact number, or should it behave like floor(a / b), and preserve the inherent inaccury present in the measured value a? Should I have floordiv preserve inaccuracy, and divmod be exact?

Any and all feedback welcome, particularly from anyone who might actually use the Measure class. ;)

~Ethan
.



Relevant Pages

  • Re: Unstable Simultaneous Linear Equations!
    ... Given: (exact 7 significant digits) ... I'll provide you with an Excel plot showing the ... The results and calculations shown in the Mathematica result are quite accurate, ...
    (sci.math.num-analysis)
  • Re: This calculation is just wrong / computer cant count!
    ... By your standards it could be argued that .83333333333333 is not correct because you can always add another 3 to the end so unless you can take the decimal places to infinity you can not have an exact value. ... Again I stress that nothing beyond the second decimal point counts and to try to include values beyond the proper number of significant digits is just plain wrong. ... Then you need to go back to primary school mathematics classes! ... Millions of PCs need to be recalled because "the math is wrong". ...
    (microsoft.public.vc.mfc)
  • Re: Error: PHP math operation
    ... My bet is that 55-55 would come out exact. ...  An IEEE double has about 15 significant digits ... more information on rounding in floats. ...
    (comp.lang.php)