Crates.io | perplex_num |
lib.rs | perplex_num |
version | 0.1.0 |
source | src |
created_at | 2024-03-29 02:39:30.415366 |
updated_at | 2024-03-29 02:39:30.415366 |
description | Perplex (hyperbolic or split-complex) numbers based on num-traits |
homepage | https://github.com/tomtuamnuq/perplex_num |
repository | https://github.com/tomtuamnuq/perplex_num |
max_upload_size | |
id | 1189608 |
size | 332,392 |
perplex_num
is a Rust crate that provides an implementation of perplex numbers, based on the numerical abstractions of the num_traits crate. This library supports various mathematical functions such as pow
, sqrt
, exp
, ln
, sinh
, sin
, cosh
, and tan
. Additionally, the crate offers a hyperbolic polar form for representing and manipulating numbers in the hyperbolic plane, as well as a matrix form representation feature based on nalgebra.
For an in-depth explanation (including visualizations) of perplex numbers and how they integrate with the crate's modules, see the Perplex Number Description in the repository.
Perplex
struct is equipped with a comprehensive set of common mathematical operations, courtesy of std::ops
and num_traits
.nalgebra::Complex
, the Perplex
struct mirrors most functions found in the num_complex crate, maintaining consistent naming conventions.cargo add perplex_num
or add this to Cargo.toml
:
[dependencies]
perplex_num = "0.1"
The matrix
feature is enabled by default, which adds the nalgebra
crate as a dependency. This can be disabled with:
[dependencies.perplex_num]
perplex_num = "0.1"
default-features = false
The examples
directory contains various practical demonstrations of how to use the perplex_num
crate. These examples not only illustrate the usage of perplex numbers but also show how to produce visualizations as seen in the Perplex Number Description.
For instance, examples/visualize_functions.rs
is executed by the following command:
cargo run --example visualize_functions
This will generate an image that depicts the behavior of functions like sinh
, cos
, inv
, and exp
when applied to perplex numbers.
Here's a quick example of how to get started with creating a perplex number and performing basic operations:
use perplex_num::Perplex;
fn main() {
// Create a Perplex number with real part 1.0 and hyperbolic part 0.5
let z = Perplex::new(1.0, 0.5);
// Calculate the hyperbolic sine of the perplex number
let z_sinh = z.sinh();
// Raise the perplex number or it's inverse to the power of 2
let z_squared = z.powu(2);
let z_inv_squared = z.powi(-2).expect("z is invertible");
println!("The hyperbolic sine of {} is {:.5}", z, z_sinh);
println!("{} raised to the power of 2 is {:.3}", z, z_squared);
println!("{} raised to the power of -2 is {:.3}", z, z_inv_squared);
}
Test coverage report is generated with cargo tarpaulin. Invoke it with:
cargo tarpaulin --verbose --all-targets --skip-clean --exclude-files "examples/*.rs" "benches/*.rs"
The perplex_num
crate is tested for rustc 1.76.