graydon/rust — Issue #1284: Implement complex numbers
Author: boggle
Created: 2011-12-10 19:29:19+00:00
State: open

Complex numbers in C are implemented by passing real and imaginary part as two consecutive, unpadded floating point values via the stack (similar for return). However, tuples in rust are defined to have the same alignment behavior as records. This means a (f32, f32) complex might suffer padding and is thus not suitable for implementing complex values. I see four ways to deal with this and would like comments on which is best:

1. Implement native complex types (complex, c32, c64) in rust. Shouldn't be too hard but is a substantial language change
2. Define tuple components to be stored consecutively (i.e. without padding/alignment)
3. Solve via annotation when declaration function prototypes in native mods
4. Natively support c_vec (stack and heap allocated)

I'm for (1) or (3), though (4) might be desirable for other reasons