I have noticed a small error on some arithmetic calculations using double. It is really weird, there's always a small error and/or an extra significant digit.
First I am using atof to convert a number that has two significant digits that I am reading from a text file (then I record them on a vector):
// Puts into vector
double ask_file, bid_file; // Values of ask and bid from file
double cur_conversion = 0.16;
ask_file = cur_conversion*atof(values[0].c_str());
bid_file = cur_conversion*atof(values[1].c_str());
Then I am doing the arithmetic (from other class, two different objects):
diff = OKC->bid_val() - BV->ask_val(); // diff
diff2 = OKC->ask_val() - BV->bid_val(); // diff2
This is the output:
BV Askfile: 245.267 Bidfile: 245.078
OKC Askfile: 248.82 Bidfile: 248.73
diff: 3.4628 diff2: 3.7416
As you can see, there's an error on both calculations. diff = 3.463 and NOT 3.4628. And diff2 = 3.742 and NOT 3.7416.
Do you know what's going on??