March 5th, 2013, 07:43 AM

Accuracy and Libraries
Hi, I'm not that knowledgeable on c so any help would be much appreciated. I've written my code in c through windows 7 and using visual studio.
My issue is that I've been informed that my code requires greater than double precision to present accurate results as we're dealing with extremely small numbers(10^25) and i would require lots of decimal places. Thus I need greater accuracy and I believe that to do that I would have to use libraries?
I've looked around and I think installing and using something like gmp sounds like it would solve this problem.
The problem is I don't really know how to use or install gmp and I don't even know if this is along the right lines so any help would be really useful.
March 5th, 2013, 12:10 PM

gmp solves the "number of decimal places" problem.
Floating point handles large and small exponents.
You might truly need 100 decimal places or whatever. More likely you've got a bad algorithm or should view the problem differently. For instance in "find the sum of the first ten thousand Fibonacci numbers mod 10e6" you don't need extra decimal places. Or "solve Ax=b for a finite element problem based on badly shaped elements" you need to remesh, not use extra decimal places.
[code]
Code tags[/code] are essential for python code and Makefiles!
March 5th, 2013, 03:10 PM

Originally Posted by arkhamshock
My issue is that I've been inormed that my code requires greater than double precision to present accurate results as we're dealing with extremely small numbers(10^25) and i would require lots of decimal places.
You have been informed incorrectly  or possibly you mis interpreted ot misrepresented the advice. The smallest representable value of double is (typically, depending on representation): 2.2250738585072014e308; many orders of magnitude smaller than you need.
Precision is not the same as magnitude, and it is not about how many zeros follow the decimal point (that would be true of fixed point but not floating point representations) . The double type is good for 15 significant figures regardless of magnitude. Note that unless you specifiy the required output precision, standard output functions such as printf() will display fewer significant figures.
In the event that you do indeed need greater precision for reasons that you have not clearly expressed here, then your compiler may support long double, which is good for 20 significant figures on x86 architectures. Beyond that you will need arbitrary precision library support, but your argument for doing so is not clear, and on the face of it you don't need one.
March 7th, 2013, 12:07 PM

Originally Posted by clifford
You have been informed incorrectly  or possibly you mis interpreted ot misrepresented the advice. The smallest representable value of double is (typically, depending on representation): 2.2250738585072014e308; many orders of magnitude smaller than you need.
Precision is not the same as magnitude, and it is not about how many zeros follow the decimal point (that would be true of fixed point but not floating point representations) . The double type is good for 15 significant figures regardless of magnitude. Note that unless you specifiy the required output precision, standard output functions such as printf() will display fewer significant figures.
In the event that you do indeed need greater precision for reasons that you have not clearly expressed here, then your compiler may support long double, which is good for 20 significant figures on x86 architectures. Beyond that you will need arbitrary precision library support, but your argument for doing so is not clear, and on the face of it you don't need one.
Thank you for getting back to me and allow me to explain myself better. I think I need it for more than 15 or 20 significant figures. I have an equation in my code which is essentially: a=12*abs(x(1)x(2))
where x(1) and x(2) change each iteration and x(n) is an array of n elements. My model is such that eventually x(1) and x(2) should be the same number. If my x(1) and x(2) aren't accurate to more than 15 significant figures they will essentially cancel each other out in the equation above. That is what I believe is causing accuracy issues in the rest of my code.
If that's the case then I definitely need library support so thanks for clearing that up. :)
I think I've set up mpir on my computer correctly. Do you know any other libraries that would be more appropriate/simpler for my task that could be easily set up or used on a windows machine? Using mpir I feel I'll have to go all the way through my code and change everything. Not an easy task for a code that simulates synchronisation in the brain :P