num-notation offers multiple numeric choices, allowing you to work with various number representations including StandardForm, fractions, and f64 floating-point decimals. This versatile crate empowers your Rust projects with flexible numeric handling.
Easily switch between different numeric choices, including:
num_traits
crate for advanced numeric operations.To use num-notation in your Rust project, simply add it to your Cargo.toml
:
toml
[dependencies]
num-notation = "0.1"
To enable intergation it with num_traits
, enable num
feature:
toml
[dependencies]
num-notation = { version = "0.1" , features = ["num"] }
Creating Numbers
rust
// Create numbers using the Number enum variants
let decimal_number = Number::Decimal(42.0);
let standard_form_number = Number::StandardForm(StandardForm::new(1.23, 2)); // Mantissa: 1.23, Exponent: 2
let fraction_number = Number::Fraction(Fraction::new(3, 4)); // Numerator: 3, Denominator: 4
You can create numbers using the Number
enum variants. Here, we create instances of decimal, standard form, and fraction numbers.
Performing Arithmetic Operations
```rust // Perform arithmetic operations let result = decimalnumber + standardform_number; // Adds a decimal and a number in standard form println!("Result: {:?}", result);
```
Extracting Values
```rust // Extract values if let Number::Decimal(d) = decimal_number { println!("Decimal value: {}", d); }
if let Number::StandardForm(sf) = standardformnumber { println!("StandardForm mantissa: {}, exponent: {}", sf.mantissa(), sf.exponent()); }
if let Number::Fraction(fr) = fraction_number { println!("Fraction numerator: {}, denominator: {}", fr.numerator(), fr.denominator()); }
```
Comparing Numbers
```rust // Compare numbers let num1 = Number::Decimal(5.0); let num2 = Number::StandardForm(StandardForm::new(500.0, -2)); // 500.0e-2 = 5.0 if num1 == num2 { println!("Numbers are equal."); } else { println!("Numbers are not equal."); }
```
Please note that the examples provided here are simplified and serve as a starting point. For comprehensive documentation of the crate, please visit the crate documentation for a better understanding of the crate's functionalities and APIs.
While we strive to cover as many scenarios as possible, the complexity of mathematics means that achieving 100% accuracy in all cases and operations can be challenging. If you come across any issues or inaccuracies in the library, please don't hesitate to report them so that we can work on improving it. Your feedback is invaluable in helping us make the necessary enhancements.
Contributions are welcome! If you find a bug or have an enhancement in mind, feel free to open an issue or submit a pull request.