Skip to content

Implement complex numbers #1284

Closed
Closed
@boggle

Description

@boggle

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

  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), or
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions