Complex number in rust language

how to represent complex number and imaginary number in rust lang
how to perform various operations in complex number

Try:

https://docs.rs/num-complex/0.2.4/num_complex/struct.Complex.html

1 Like

Complex Numbers as predefined datatype

While i was reading about datatype in go-lang on a blog i notice a feature to represent complex number which is a predefined architecture-independent float types and also perform various operations in complex number simple using + , - etc... more details on link below : https://www.callicoder.com/golang-basic-types-operators-type-conversion/#complex-numbers

i feel that adding or adopting this feature to rust language will really help the the users and developers while solving Mathematics related problem.
i feel instead of using an external carte for a complex number problem using complex number as a predefined datatype is a good feature.

This is just a proposal form a my side,i am not trying to compare rust and go or with any other language . if rust developers feel it is a relevant please accept it else simply reject it.

Go doesn't have generics or operator overloading, so it has to make complex numbers a language built-in.

In Rust, a library can do operator overloading, so such features don't need to burden the core language.

The only difference is that Rust can't have a nice syntax for literals such as 7i. This could be solved by allowing crates to have their own literals.

Rust tries to do as much as possible using external crates, to keep the language and standard library lean. You can't write any meaningful Rust program without external crates, so avoidance of crates is not a good enough reason to make something built-in in Rust.

4 Likes

Were Rust to add complex numbers as something intrinsic, then the next similar request would probably be to add quaternions. Rust provides the tools for users to add such items, generally in crates on crates.io that are shared with the rest of the Rust community. My favorite example of such additions that extend the concept-set of elementary items is uom (Units of Measurement).

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.