> And for different types this is pretty normal as you can have > x == 0.2 // true > y = int(x) > float64(y) != 0.2 // true too
A more correct analogy would've been: var x := 0.2 var y := float32(x) math.IsNaN(float64(y)) // true in this analogy > It is a property of all float types I used floats as an example of type with such "kaboom" value. > For the rest of the argument: It _really_ isn't an actual problem. In 10 years of Go this happened maybe three time to me and was dead simple to identify. I faced this issue twice. Once caused by my code and the other by not mine. Second time it wasn't that simple to identify because Schroedingerface travelled quite a long distance from its birthplace. Anyway, this issue seems to get raised repeatedly. On Thursday, August 27, 2020 at 2:16:34 PM UTC+3 Volker Dobler wrote: > On Thursday, 27 August 2020 11:39:11 UTC+2, targe...@gmail.com wrote: >> >> To me, if `x == nil` and then `y != nil` after `y = x` is much more >> confusing. >> > > This can happen only if x and y have different types. > And for different types this is pretty normal as you can have > x == 0.2 // true > y = int(x) > float64(y) != 0.2 // true too > With the only difference that you have explicit type conversions > where interface assignment is implicit. > > And this is not even the strangest thing that can happen: > NaN floats are especially peculiar. You can have > x := y > x != y // true > x != x // also true > > That is something everybody has to learn once. It is a > property of all float types. Different types behave differently. > And this is true not only for operators like +, - or / but also > for operators like =, == and !=. > > For the rest of the argument: It _really_ isn't an actual > problem. In 10 years of Go this happened maybe three > time to me and was dead simple to identify. > > V. > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3efd9d39-0360-4efc-b47e-54482cd7dd35n%40googlegroups.com.