the situation is drammatic... It's 5 days that i must resolve this problem and i can't get out.
The problem: a simple operation as a product make always wrong result. Why?
Extract of the code:
//all vars are float
// resultVec is a vector [3]
// Rs is a vector [3]
// accelerationvalues is a vector [3]
resultVec[0]=Rs[0]*accelerationvalues[0]+Rs[1]*accelerationvalues[1]+Rs[2]*accelerationvalues[2];
//debug to print result
Log.d("e", "("+Rs[0]+")*("+accelerationvalues[0]+")+("+Rs[1]+")*("+accelerationvalues[1]+")+("+Rs[2]+")*("+accelerationvalues[2]+")="+(resultVec[0]));
And this is the Log Cat result: But you can simply try that this is wrong: search on google
(0.040147018)*(-0.9942854)+(0.9984244)*(-0.32688835)+(0.039202508)*(9.343558)
And you'll find that the true result is 8.67678679 × 10-9 that is very different from the other..This error is repeated always i execute the programm, some time the difference is in the sign too!
What is the problem?
I've tried all the way to solve it! (some are posted below):
You can find the full source here.
- save Rs and accelerationvalues in an arraylist and perform calculation outside the listner. No result.
- Convert float to double, no result.
- Many others ways
P.S. This problem occour only for resultVec[0]
and resultVec[1]
, instead resultVec[2]
is well calculated.