Question

what is the best practice to check for numerical precision in algorithms? Is there any suggested technique to resolve the problem "how do we know the result we calculated is correct"? If possible: are there some example of numerical precision enhancement in C++?

Thank you for any suggestion!

Was it helpful?

Solution

Math::BigFloat / Math::BigInt will help. I must say there are many libraries that do this, I don't know which would be best. Maybe someone else has a nice answer for you.

In general though, you can write it twice: once with unlimited precision, and one without then verify the two. That's what I do with the scientific software I write. Then I'll write a third that does fancier speed enhancements. This way I can verify all three. Mind you, I know the three won't be exactly equal, but they should have enough significant figures of corroboration.

To actually know how much error is difficult to obtain accurately --remember order of operations of floating point numbers can cause large differences. It's really problem specific but if you know the relative magnitude of certain numbers you can change the order of operations to get accuracy (multiply a list in sorted order for example). Two places to look for investigating this is,

OTHER TIPS

Have a look at interval arithmetic, for example

http://www.boost.org/doc/libs/1_53_0/libs/numeric/interval/doc/interval.htm

It will produce upper and lower bounds on results

PS: also have a look at http://www.cs.cmu.edu/~quake/robust.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top