Link to home
Start Free TrialLog in
Avatar of Zeman4323
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
Avatar of jkr
jkr
Flag of Germany image

>>I want to subtract 4e-12 from 10.

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>::epsilon() << endl;
 
ASKER CERTIFIED SOLUTION
Avatar of wayside
wayside

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of grg99
grg99

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?

Avatar of Zeman4323

ASKER

well i needed it for a school assignment (doesn't really need to be precise)  But setprecision(17) works perfect.

Thanks