Why not just use a struct? I personally dislike the idea of Rust implicitly generating additional function calls. Explicit is better than implicit, IMO. When I call csin(complex)
it should be exactly that.
Personally I don't think this is any simpler than just introducing a new ComplexF32
/ComplexF64
type.
For prior discussions, there's RFC 793
Alternatively, the C standard requires complex types to have "the same representation and alignment requirements as an array type containing exactly two elements of the corresponding real type." Since arrays aren't first-class types in C, it means Rust should have some flexibility in how it interprets the ABI of [f32; 2]
/[f64; 2]
. Rust could just declare these two types as having the same ABI as float _Complex
/double _Complex
.