Thursday, December 4, 2008

High-precision math

I was wondering a couple of months ago about how to achieve accuracy in floating-point computations such as say, try to multiple 4.34524362 with 2.456357642456 while we know that there is only finite precision that can be provided by programming languages. A way around this problem was to save the values as strings and multiple two strings rather than two numbers - so you won't be able to multiply two "values" a and b as a*b but you multiply them as multiply(a,b). Using operator overloading, even a*b can easily be achieved. Now, what I have done so far is +,-,*,/, factorial, combinations on integers and being too lazy, I only implemented the * functions on floating-point values. The implementation works for extremely large values (as high as the compiler would support for a string - which is pretty high :D)

The math_library.cpp (right click and choose "save target as") can be used by anyone but NOT for commercial purposes.

No comments:

Related Posts with Thumbnails