Sorry, this is nothing about image, I just don’t know how to ask the question properly.
My question is, I am writing a C++ code, and doing a calculation.
a=b*cos(c)
b is varying with time from zero to its amplitude, say bmax. (actually, b=bmax*sin(t).)
However, I found when b is very small, the result a is gradually deviating from my analytic results.
So I am wondering how to keep a very high resolution of the results, to avoid the cut-off of the floating points.
When you say it’s gradually deviating it sounds like you’ve got an accumulation of error there (although there’s nothing obvious in the code you posted). For example this code the error accumulates with every iteration around the while loop:
Where as re-writing it like:
does not cause this accumulation of error as
valonly depends upon the integer (which is exactly representable) and not the previous values ofvaleach of which will have introduced some small error.