issue about ismember wrong output
1 ビュー (過去 30 日間)
Walter Roberson 2020 年 3 月 24 日
You forgot that in binary floating point representation there is no exact equivalent to 0.1 or 0.01 or 0.02, only approximations of those. When you add up those approximations of 0.01 you are not necessarily going to get exactly an approximation of 0.02 especially since you start the 0.02 accumulation at a different start point.
Consider the analogy in decimal of 1/3 to two decimal places. 1/3 decimal is 0.33333333 with the 3 infinitely repeated. To two decimals, 0.33. Now add another of the same to that and you get 0.66. Is that the same as the 2 decimal approximation of 2/3? No, the 2 decimal approximation of 2/3 is 0.67. This illustrates that when you add up truncated approximations that you do not necessarily get the same as the direct value.
The moral of the story is to avoid exact comparisons in floating point. See ismembertol