pub fn primitive_floats_increasing<T: PrimitiveFloat>(
) -> PrimitiveFloatIncreasingRange<T>Notable traits for PrimitiveFloatIncreasingRange<T>impl<T: PrimitiveFloat> Iterator for PrimitiveFloatIncreasingRange<T> type Item = T;
Expand description

Generates all primitive floats, except NaN, in ascending order.

Positive and negative zero are both included. Negative zero comes first.

NEGATIVE_INFINITY is generated first and POSITIVE_INFINITY is generated last. The returned iterator is double-ended, so it may be reversed.

Let $\varphi$ be to_ordered_representation:

The output is $(\varphi^{-1}(k))_{k=0}^{2^{M+1}(2^E-1)+1}$.

The output length is $2^{M+1}(2^E-1)+2$.

  • For f32, this is $2^{32}-2^{24}+2$, or 4278190082.
  • For f64, this is $2^{64}-2^{53}+2$, or 18437736874454810626.

Complexity per iteration

Constant time and additional memory.

Examples

use malachite_base::iterators::prefix_to_string;
use malachite_base::num::basic::floats::PrimitiveFloat;
use malachite_base::num::exhaustive::primitive_floats_increasing;
use malachite_base::num::float::NiceFloat;

assert_eq!(
    prefix_to_string(primitive_floats_increasing::<f32>().map(NiceFloat), 20),
    "[-Infinity, -3.4028235e38, -3.4028233e38, -3.402823e38, -3.4028229e38, -3.4028227e38, \
    -3.4028225e38, -3.4028222e38, -3.402822e38, -3.4028218e38, -3.4028216e38, -3.4028214e38, \
    -3.4028212e38, -3.402821e38, -3.4028208e38, -3.4028206e38, -3.4028204e38, -3.4028202e38, \
    -3.40282e38, -3.4028198e38, ...]"
);
assert_eq!(
    prefix_to_string(primitive_floats_increasing::<f32>().rev().map(NiceFloat), 20),
    "[Infinity, 3.4028235e38, 3.4028233e38, 3.402823e38, 3.4028229e38, 3.4028227e38, \
    3.4028225e38, 3.4028222e38, 3.402822e38, 3.4028218e38, 3.4028216e38, 3.4028214e38, \
    3.4028212e38, 3.402821e38, 3.4028208e38, 3.4028206e38, 3.4028204e38, 3.4028202e38, \
    3.40282e38, 3.4028198e38, ...]"
);