Function malachite_base::num::exhaustive::exhaustive_nonzero_signeds
source · pub fn exhaustive_nonzero_signeds<T: PrimitiveSigned>() -> PrimitiveIntUpDown<T>
Expand description
Generates all nonzero signed integers in order of increasing absolute value.
When two numbers have the same absolute value, the positive one comes first.
The output satisfies $(|x_i|, \operatorname{sgn}(-x_i)) <_\mathrm{lex} (|x_j|, \operatorname{sgn}(-x_j))$ whenever $i, j \in [-2^{W-1}, 2^{W-1}) \setminus \{0\}$, where $W$ is the width of the type, and $i < j$.
The output length is $2^W-1$.
§Complexity per iteration
Constant time and additional memory.
§Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::exhaustive::exhaustive_nonzero_signeds;
assert_eq!(
prefix_to_string(exhaustive_nonzero_signeds::<i8>(), 10),
"[1, -1, 2, -2, 3, -3, 4, -4, 5, -5, ...]"
)