Hello, Conversion to complex numbers should be done with the complex builtin function, specifying a real and imaginary part. However, is casting to a complex type supported or not? Empirically, it seems to me that sometimes it is and sometimes it isn't. More confusing is that this behaviour changed between version 1.13.6 and 1.14.
Using this test program. package main import "testing" // int -> complex const constInt = 1 func TestConstInt(t *testing.T) { _ = complex64(constInt) } const constIntExplicit = int(1) func TestConstIntExplicit(t *testing.T) { _ = complex64(constIntExplicit) } func TestVarInt(t *testing.T) { varInt := 1 _ = complex64(varInt) } func TestVarIntExplicit(t *testing.T) { varIntExplicit := int(1) _ = complex64(varIntExplicit) } // float -> complex const constFloat = 1 func TestConstFloat(t *testing.T) { _ = complex64(constFloat) } const constFloatExplicit = float64(1) func TestConstFloatExplicit(t *testing.T) { _ = complex64(constFloatExplicit) } func TestVarFloat(t *testing.T) { varFloat := 1 _ = complex64(varFloat) } func TestVarFloatExplicit(t *testing.T) { varFloatExplicit := float64(1) _ = complex64(varFloatExplicit) } Summary of results: 1.13.6 1.14.1 const int y y const int (explicit type) y n variable int n n variable int (explicit type) n n const float y y const float (explicit type) y n variable float n n variable float (explicit type) n n I wouldn't want to argue too strongly on this point but for consistency, should casting be allowed at all? Regards Stephen Illingworth -- 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/e09492c7-bbb0-4ff7-865f-d3d7ea57937f%40googlegroups.com.