hi,
working on a simulation patch i've difficulties with wrong results from additions.
in a periodic loop a [value V] is added up with a constant.
a simplified version:
[t b] - [v V] - [+ 0.0025] - [v V]
it starts at 0.
looking at the numbers when put in an array i see that e.g.
the value that should be 0.1250 is actually 0.1249999
and 0.75 is actually 0.7499994.
in the loop this variable is used for calculations which multiply the deviations.
why does this simple addition not giving the exact result?
rolf
On Wed, 2021-05-19 at 13:38 +0200, rolfm@dds.nl wrote:
the value that should be 0.1250 is actually 0.1249999
and 0.75 is actually 0.7499994.
The intricacies of 32bit floating point numbers have been discussed up and down on this list.
tldr; many decimal numbers do not have an exact floating point representation. Incrementing with such numbers increases the error on each iteration
Suggestion: Count with integer numbers and scale afterwards.
Roman