I think that might have already been done...in the
Math::BigInt package we find the interesting
Math::BigFloat. These modules will obey either
precision (i.e., number of digits beyond the decimal point) as well as
accuracy (i.e., significant digits/figures). That's their choice of terminology, precision vs. accuracy. I'm not sure if they properly apply the rules for sig figs when you get a new float from an operation involving two values with different sig figs.
I /msg'd you about this, but as I've thought more about this I like the name snap() for the function in question (yea, even better than fudge()). Because really, what's happening is a gravitation towards more psychologically appealing numbers -- no different than applying a layout grid on a canvas, and having things 'snap' towards the grid lines.
The problem with the BigInt stuff is probably always going to be speed (this is speculation on my part). Perhaps you can use native floats unless specified otherwise, in which case the operations shift into Math::BigFloat mode. (this should be reasonably transparent since the BigInt modules override operators for DWIMery).
Oh, also -- I found Math::FixedPrecision, which is built on top of Math::BigFloat. It appears to simplify precision math, i.e., nail down the number of decimal places. I see an analagous need here for a 'Math::SigFig' or somesuch. I notice that John Peacock, the author of Math::FixedPrecision, is also the author of Math::Currency -- one obvious application of precision arithmetic vs. significant figures.
Matt
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.