Closed
Description
Complex numbers in C are implemented by passing real and imaginary part as two consecutive, unpadded floating point values via the stack (i.e. as length-2 array). This is similar for returned complex values - which is the catch, as tuples in rust are defined to have the same alignment behavior as records (cf spec). This means a (f32, f32) complex might suffer padding and is thus not suitable for implementing complex values. I see different ways to deal with this and would like comments on which is best
- Implement native complex types (complex, c32, c64) in rust. Shouldn't be too hard but is a substantial language change,
- Define tuple components to be stored consecutively (i.e. without padding/alignment),
- Solve via annotation when declaration function prototypes in native mods,
- Natively support c_vec (stack and heap allocated), or
- Implement tuple-based wrappers in the runtime.
I'm tending to favor (1) though (3) and (4) might be desirable to have for other reasons.