jtk207
asked on
Adding large numbers
I have the following c++ program:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double long i=0.0000000000000000000035 ;
double long j=3.24433466545467;
j+=i;
cout<<setprecision(100)<<j <<endl;
return 0;
}
why does it print: 3.24433466545467
instead of: 3.2443346654546700000035
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double long i=0.0000000000000000000035
double long j=3.24433466545467;
j+=i;
cout<<setprecision(100)<<j
return 0;
}
why does it print: 3.24433466545467
instead of: 3.2443346654546700000035
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So how would i fix it?
Directly, you can't. You'd have to get or write an algorithm to deal with arbitrarily large/small numbers. I've seen these for integers, but I haven't seen one for reals. Is that amount of precision really necessary for what you're doing?
http://www.fact-index.com/i/ie/ieee_floating_point_standard.html#Double%20Precision%2064%20bit