Zeman4323
asked on
Subtracting small numbers
I think this is really simple and trivial.
I have a program with 10.0 as a double value.
I want to subtract 4e-12 from 10.
I am not sure how to do this. When I convert this number to decimal form and try subtracting it it also doesn't work. The number always remains 10.
I am guessing that I am loosing precision or something to this effect.
If anyone knows how to do this that would be extremely helpful.
Thanks a lot
~Matthew
I have a program with 10.0 as a double value.
I want to subtract 4e-12 from 10.
I am not sure how to do this. When I convert this number to decimal form and try subtracting it it also doesn't work. The number always remains 10.
I am guessing that I am loosing precision or something to this effect.
If anyone knows how to do this that would be extremely helpful.
Thanks a lot
~Matthew
BTW, if you need a higher precision, take a look at
http://www.cs.unc.edu/Research/HARPOON/mpfun++/
http://www.swbic.org/products/bioinfo/extnum/extnum.php
http://www.cs.unc.edu/Research/HARPOON/mpfun++/
http://www.swbic.org/products/bioinfo/extnum/extnum.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also think about whether this is of any use. There are very few places where numbers are known to be accurate to 4 parts in 10 million million. Perhaps you don't need all that resolution?
ASKER
well i needed it for a school assignment (doesn't really need to be precise) But setprecision(17) works perfect.
Thanks
Thanks
That's *way* below the numeric resolution your PC can handle, the minimum is described as 'numeric_limits::epsilon
()', e.g.
#include <iostream>
#include <limits>
using namespace std;
cout << "The epsilon for double is " <<
numeric_limits<double>::ep