mixed_num/
lib.rs

1//! No-STD abstraction layer enabling numerical functions to be implemented once, and simultaneously support both real and complex numbers with, int, fixed and floating point types.
2//! 
3//! This is an experimental library.
4//! 
5//! ## Example
6//! 
7//! ```
8//! use mixed_num::*;
9//! use mixed_num::traits::*;
10//! use fixed::{types::extra::U27, FixedI32};
11//! 
12//! let number = FixedI32::<U27>::from_num(0.6f32);
13//! let res:f32 = number.mixed_atan().mixed_to_num();
14//! 
15//! assert_eq!{ res, 0.5404195 };
16//! 
17//! let number = 0.6f32;
18//! let res:f32 = number.mixed_atan().mixed_to_num();
19//! 
20//! assert_eq!{ res, 0.5404195 };
21//! ``` 
22//! 
23//! 
24//! The library supplies complex structs `Polar<T>` and `Cartesian<T>` with no-std implementation of math traits, including `MixedNum` traits.
25//! 
26//! Some interoperability with num::Complex is implemented.
27//! 
28//! ## Example
29//! 
30//! ```
31//! use mixed_num::*;
32//! use mixed_num::traits::*;
33//! 
34//! let number = Cartesian::new(1f32,2f32);
35//! 
36//! assert_eq!{ number.to_string(), "1+2i" };
37//! 
38//! let polar_number = number.to_polar();
39//! assert_eq!{ polar_number.to_string(), "2.236068∠1.1071488" };
40//! 
41//! let polar_conj: Polar<f32> = polar_number.conj();
42//! 
43//! assert_eq!{ polar_conj.to_string(), "2.236068∠-1.1071488" };
44//! ``` 
45//! 
46//! Selected `core::ops` traits are implemented on the complex structs.
47//! 
48//! ## Example
49//! 
50//! ```
51//! use mixed_num::*;
52//! use mixed_num::traits::*;
53//! 
54//! let mut c_num = Cartesian::new(1f32,2f32);
55//! 
56//! c_num = c_num*c_num;
57//! assert_eq!{ c_num.to_string(), "-3+4i" };
58//! ```
59//! 
60//! This includes support for operation of mixed types.
61//! 
62//! ## Example
63//! 
64//! ```
65//! use mixed_num::*;
66//! use mixed_num::traits::*;
67//! 
68//! let mut c_num = Cartesian::new(1f32,2f32);
69//! 
70//! c_num = c_num*2f64;
71//! assert_eq!{ c_num.to_string(), "2+4i" };
72//! ``` 
73
74#![crate_name = "mixed_num"]
75#![no_std]
76
77#[cfg(feature = "std")]
78extern crate std;
79
80pub mod trigonometry;
81
82pub mod traits;
83pub use traits::*;
84
85mod float_impl;
86pub use float_impl::*;
87
88mod fixed_impl;
89pub use fixed_impl::*;
90
91pub mod complex;
92#[allow(unused)]
93pub use complex::*;
94
95mod int_impl;
96pub use int_impl::*;