33 releases
0.12.0 | Aug 13, 2024 |
---|---|
0.11.1 | Dec 20, 2023 |
0.11.0 | Nov 6, 2023 |
0.10.0 | Jul 3, 2023 |
0.3.0 | Feb 1, 2021 |
#112 in Math
1,868 downloads per month
Used in 16 crates
(4 directly)
125KB
4K
SLoC
number-general
A generic Rust number type with support for basic math operations, (de)serialization, and casting with safecast.
Example usage:
use number_general::{Int, Number};
use safecast::CastFrom;
let sequence: Vec<Number> = serde_json::from_str("[true, 2, 3.5, -4, [1.0, -0.5]]").unwrap();
let actual = sequence.into_iter().product();
assert_eq!(actual, Number::from(num::Complex::<f64>::new(-28., 14.)));
assert_eq!(Int::cast_from(actual), Int::from(-28));
lib.rs
:
Provides a generic Number
enum with Boolean
, Complex
, Float
, [Int
],
and UInt
variants, as well as a NumberCollator
, ComplexCollator
, and
FloatCollator
since these types do not implement [Ord
].
Number
supports casting with safecast
.
For (de)serialization with serde
, enable the "serde"
feature.
For (de)coding with destream
, enable the "stream"
feature.
Example usage:
let sequence: Vec<Number> = vec![true.into(), 2.into(), 3.5.into(), [1.0, -0.5].into()];
let actual = sequence.into_iter().product();
let expected = Number::from(num::Complex::<f64>::new(7., -3.5));
assert_eq!(expected, actual);
assert_eq!(Int::cast_from(actual), Int::from(7));
Dependencies
~1.2–2.2MB
~44K SLoC