It seems it's an IEEE issue
but I didn't think that -0.2 + 0.1 would qual -0.0999999999999996
so what I am doing is creating a coordinate map of (-3,-3) to (3,3) where intervals are 0.1. I can simply solve this issue by rounding the results (and I can enhance it by only rounding when there are more than 1 decimal)
I wish I didn't have to though as that adds checks on every loop, and it runs 3721 times.
for x in stride(from: min, to: max + 0.1, by: 0.1) {
for y in stride(from: min, to:max + 0.1, by: 0.1) {
let rounded_x = Double(round(x * 1000) / 1000)
let rounded_y = Double(round(y * 1000) / 1000)
print("\(rounded_x), \(rounded_y)")
coordinates[Coordinate(x: rounded_x, y: rounded_y)] = []
}
}
even stranger, this only occurs for -0.2 + 0.1, here's the full output of the inner loop:
3.0, -3.0
3.0, -2.9
3.0, -2.8
3.0, -2.7
3.0, -2.6
3.0, -2.5
3.0, -2.4
3.0, -2.3
3.0, -2.2
3.0, -2.1
3.0, -2.0
3.0, -1.9
3.0, -1.8
3.0, -1.7
3.0, -1.6
3.0, -1.5
3.0, -1.4
3.0, -1.3
3.0, -1.2
3.0, -1.1
3.0, -1.0
3.0, -0.9
3.0, -0.8
3.0, -0.7
3.0, -0.6
3.0, -0.5
3.0, -0.4
3.0, -0.3
3.0, -0.2
3.0, -0.0999999999999996
3.0, 0.0
3.0, 0.1
3.0, 0.2
3.0, 0.3
3.0, 0.4
3.0, 0.5
3.0, 0.6
3.0, 0.7
3.0, 0.8
3.0, 0.9
3.0, 1.0
3.0, 1.1
3.0, 1.2
3.0, 1.3
3.0, 1.4
3.0, 1.5
3.0, 1.6
3.0, 1.7
3.0, 1.8
3.0, 1.9
3.0, 2.0
3.0, 2.1
3.0, 2.2
3.0, 2.3
3.0, 2.4
3.0, 2.5
3.0, 2.6
3.0, 2.7
3.0, 2.8
3.0, 2.9
3.0, 3.0
I'm not sure why this occurs in the stride function, but not when adding -0.2 + 0.1, and that is what I am curious about.