Skip to content

Complex number support #752

Description

@standarddeviant

In the docs, the numeric types are INT, FLOAT, or Decimal. I'm wondering if it's aligned with the goals of the rhai project to add support for a Complex type that defaults to storing real and imaginary components as (2) f64 fields.

I'm working on a REPL that automatically loads rhai-sci, and wondering how complex matrix operations might work, and thinking it might be nice if a Complex number type was eventually built-in to rhai. There's already complex number support in nalgebra, which I believe rha-sci depends on:

Numpy and MATLAB both use "1i" or "1j" to represent an imaginary component, and this seems like good syntax - i.e. "let a = 2.0 + 1j * 3.5" would create a complex number. There would have to be some associated functions for arithmetic, sine, cosine, exponentials, etc.

Does that sound like a reasonable idea? I'm interested to prototype this and submit a PR. Any pointers on where to start or things to look for are appreciated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions