Complex Number Calculator in Rust

Your Favourite Calculator in Rust

#Rust#Projects

Complex Number Calculator in Rust

To get started in Rust, I implemented a calendar. It can perform calculations with real numbers as well as with complex numbers. It also provides some functions for calculating sums or products. I then used egui to create a GUI for it.

GUI

Users can save the arithmetic expression and its result to a file.

Generic Traits for Solids

The source code of my calculator can be extended easily to work with any solid, not just real or complex numbers. Therefore, I moved the code for performing the actual calculations into a Rust Trait solid.

pub trait Solid<T : SolidNumber<T>> : Sized { //general info fn get_solid_name() -> String; //addition fn get_neutral_element_addition() -> T; fn add(x : T, y : T) -> T; fn get_additive_inverse(x : T) -> T; //multiplication fn get_neutral_element_multiplicative() -> T; fn multiply(x : T, y : T) -> T; fn get_multiplicative_inverse(x : T) -> T; //other functions fn get_available_functions() -> Vec<(String, fn(Vec<String>)->(T, String), Vec<i32>, i32)>; }

This generic traits is used for implementing real and complex numbers:

Comments

Feel free to leave your opinion or questions in the comment section below.