Function malachite_base::num::exhaustive::primitive_float_increasing_range
source · pub fn primitive_float_increasing_range<T: PrimitiveFloat>(
a: T,
b: T,
) -> PrimitiveFloatIncreasingRange<T> ⓘ
Expand description
Generates all primitive floats in the half-open interval $[a, b)$, in ascending order.
Positive and negative zero are treated as two distinct values, with negative zero being smaller than zero.
NiceFloat(a)
must be less than or equal to NiceFloat(b)
. If NiceFloat(a)
and
NiceFloat(b)
are equal, the range is empty. This function cannot create a range that includes
INFINITY
; for that, use primitive_float_increasing_inclusive_range
.
Let $\varphi$ be
to_ordered_representation
:
The output is $(\varphi^{-1}(k))_{k=\varphi(a)}^{\varphi(b)-1}$.
The output length is $\varphi(b) - \varphi(a)$.
§Complexity per iteration
Constant time and additional memory.
§Panics
Panics if NiceFloat(a) > NiceFloat(b)
.
§Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::exhaustive::primitive_float_increasing_range;
use malachite_base::num::float::NiceFloat;
assert_eq!(
prefix_to_string(
primitive_float_increasing_range::<f32>(1.0, 2.0).map(NiceFloat),
20
),
"[1.0, 1.0000001, 1.0000002, 1.0000004, 1.0000005, 1.0000006, 1.0000007, 1.0000008, \
1.000001, 1.0000011, 1.0000012, 1.0000013, 1.0000014, 1.0000015, 1.0000017, 1.0000018, \
1.0000019, 1.000002, 1.0000021, 1.0000023, ...]"
);
assert_eq!(
prefix_to_string(
primitive_float_increasing_range::<f32>(1.0, 2.0)
.rev()
.map(NiceFloat),
20,
),
"[1.9999999, 1.9999998, 1.9999996, 1.9999995, 1.9999994, 1.9999993, 1.9999992, 1.999999, \
1.9999989, 1.9999988, 1.9999987, 1.9999986, 1.9999985, 1.9999983, 1.9999982, 1.9999981, \
1.999998, 1.9999979, 1.9999977, 1.9999976, ...]",
);