by chimeracoder · 4y ago · 0 comments
In Go, every value is stored as a tuple: (concrete type, value). So (int32, 5) is not the same as (int64, 5), even though the numeric value is the same.
In general, the compiler will prevent comparisons that are always going to be false, such as comparing an int32 to an int64: https://go.dev/play/p/q0skdfUnWsD
The only time when you'll be able to compare two entities with identical values but different concrete types (and have your code compile) is when they're being compared through variables stored in an interface: https://go.dev/play/p/t0QDFh70Ut4.
This can be surprising when you first encounter it, but once you understand how it works, it's easier to remember.
With floats being the exception
And complex as they're basically a pair of floats.
And transitively any array or struct containing one of the exceptions.
So really, == is mostly not a bitwise comparison, when you think about it.
If == on string was a bitwise comparison, it would be an identity check. But two different strings with the same content compare equal, meaning go dereferences the buffer pointer.