#dsp #radio #audio #no-std

no-std mixed-num

A trait for generic implementations of numerical methods

24 releases (4 breaking)

Uses new Rust 2021

0.5.5 Apr 22, 2022
0.5.4 Apr 4, 2022
0.4.5 Mar 31, 2022
0.3.0 Mar 27, 2022
0.1.6 Jan 30, 2022

#138 in Audio

Download history 11/week @ 2022-06-16 9/week @ 2022-06-23 15/week @ 2022-06-30 54/week @ 2022-07-07 29/week @ 2022-07-14 80/week @ 2022-07-21 46/week @ 2022-07-28 39/week @ 2022-08-04 15/week @ 2022-08-11 9/week @ 2022-08-18 55/week @ 2022-08-25 12/week @ 2022-09-01 42/week @ 2022-09-08 7/week @ 2022-09-15 11/week @ 2022-09-22 31/week @ 2022-09-29

94 downloads per month
Used in 2 crates

Custom license

110KB
2.5K SLoC

Mixed Num

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.

The library supplies complex structs Polar<T> and Cartesian<T> with no-std implementation of math traits, including MixedNum traits.

Some interoperability with num::Complex is implemented.

This is an experimental library.

This library support fixed point numbers using the fixed crate. It uses num for floating point generics.

The package.

The documentation.

Release notes are found under RELEASES.md.


lib.rs:

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.

This is an experimental library.

Example

use mixed_num::*;
use mixed_num::traits::*;
use fixed::{types::extra::U27, FixedI32};

let number = FixedI32::<U27>::from_num(0.6f32);
let res:f32 = number.mixed_atan().mixed_to_num();

assert_eq!{ res, 0.5404195 };

let number = 0.6f32;
let res:f32 = number.mixed_atan().mixed_to_num();

assert_eq!{ res, 0.5404195 };

The library supplies complex structs Polar<T> and Cartesian<T> with no-std implementation of math traits, including MixedNum traits.

Some interoperability with num::Complex is implemented.

Example

use mixed_num::*;
use mixed_num::traits::*;

let number = Cartesian::new(1f32,2f32);

assert_eq!{ number.to_string(), "1+2i" };

let polar_number = number.to_polar();
assert_eq!{ polar_number.to_string(), "2.236068∠1.1071488" };

let polar_conj: Polar<f32> = polar_number.conj();

assert_eq!{ polar_conj.to_string(), "2.236068∠-1.1071488" };

Selected core::ops traits are implemented on the complex structs.

Example

use mixed_num::*;
use mixed_num::traits::*;

let mut c_num = Cartesian::new(1f32,2f32);

c_num = c_num*c_num;
assert_eq!{ c_num.to_string(), "-3+4i" };

This includes support for operation of mixed types.

Example

use mixed_num::*;
use mixed_num::traits::*;

let mut c_num = Cartesian::new(1f32,2f32);

c_num = c_num*2f64;
assert_eq!{ c_num.to_string(), "2+4i" };

Dependencies

~3MB
~59K SLoC