It some times happen when I use floating point numbers in c++ and only use numbers as multiples of, say 0.1, as an increment in a for loop, the actual number which is the loop iterators is not exactly multiples of 0.1 but has unpredictably other added or subtracted tiny numbers of the order of 1^-17. How can I avoid that?
Share
Don’t iterate over floating-point numbers.
The problem is that 0.1 can’t be exactly represented in floating-point. So instead, you should do something like: