Logo by www.freepik.com
Magnitude - To infinity and beyond!
This crate is useful when you need to work with algorithms like
Dijkstra's Shortest Path or
Floyd–Warshall algorithm
that require infinite values in order to be written elegantly.
One simple example can be finding the max value in a vector:
use Magnitude;
let vec: = vec!;
assert_eq!;
You can do all valid comparison(==, !=, >, <, >=, <=) and arithmetic(+,-, *, /, +=, -=, *=, /=) operations on magnitudes.
Invalid operations are listed below which means any other operation is valid.
Invalid operations
- Comparison:
- two
PosInfinite - two
NegInfinite
- two
- Arithmetic:
- Add:
PosInfinite+NegInfinite
- Sub:
PosInfinite-PosInfiniteNegInfinite-NegInfinite
- Mul:
- zero *
PosInfinite - zero *
NegInfinite
- zero *
- Div:
- non-zero /
PosInfinite - non-zero /
NegInfinite PosInfinite/ zeroNegInfinite/ zeroPosInfinite/PosInfinitePosInfinite/NegInfiniteNegInfinite/PosInfiniteNegInfinite/NegInfinite
- non-zero /
- Add:
Relationship of Magnitude with f64 and f32 infinities
Magnitude as of 0.2.0 treat f64::INFINITY, f64::NEG_INFINITY, f32::INFINITY, f32::NEG_INFINITY as infinites:
use Magnitude;
let pos_inf: = f64INFINITY.into;
let neg_inf: = f64NEG_INFINITY.into;
assert!;
assert!;
let pos_inf: = f32INFINITY.into;
let neg_inf: = f32NEG_INFINITY.into;
assert!;
assert!;
Release
- 0.2.0: handle
f64::INFINITY,f64::NEG_INFINITY,f32::INFINITY,f32::NEG_INFINITYproperly
special thanks to @niklasmohrin and @smarnach