Skip to main content

random_non_positive_finite_floats

Function random_non_positive_finite_floats 

Source
pub fn random_non_positive_finite_floats(
    seed: Seed,
    mean_sci_exponent_abs_numerator: u64,
    mean_sci_exponent_abs_denominator: u64,
    mean_precision_numerator: u64,
    mean_precision_denominator: u64,
    zero_p_numerator: u64,
    zero_p_denominator: u64,
) -> RandomNonPositiveFiniteFloats<RandomNaturals<GeometricRandomNaturalValues<u64>>> 
Expand description

Generates random non-positive finite Floats.

Simpler Floats (those with a lower absolute sci-exponent or precision) are more likely to be chosen. You can specify the numerator and denominator of the probability that a zero will be generated. You can also specify the mean absolute sci-exponent and precision by passing the numerators and denominators of their means of the nonzero Floats.

But note that the specified means are only approximate, since the distributions we are sampling are truncated geometric, and their exact means are somewhat annoying to deal with. The practical implications are that

  • The actual means are slightly lower than the specified means.
  • However, increasing the specified means increases the actual means, so this still works as a mechanism for controlling the sci-exponent and precision.
  • The specified sci-exponent mean must be greater than 0 and the precision mean greater than 2, but they may be as high as you like.

Negative zero is generated, but positive zero is not. NaN is not generated either.

The output length is infinite.

§Expected complexity per iteration

$T(n, m) = O(n + m)$

$M(n, m) = O(n / m)$

where $T$ is time, $M$ is additional memory, $n$ is mean_precision_numerator, and $m$ is mean_precision_denominator.

§Examples

use itertools::Itertools;
use malachite_base::random::EXAMPLE_SEED;
use malachite_float::float::random::random_non_positive_finite_floats;
use malachite_float::ComparableFloat;

// The number after the '#' is the precision.
assert_eq!(
    random_non_positive_finite_floats(EXAMPLE_SEED, 10, 1, 10, 1, 1, 10)
        .take(20)
        .map(|f| ComparableFloat(f).to_string())
        .collect_vec()
        .as_slice(),
    &[
        "-1.11e5#5",
        "-0.03108048#17",
        "-9.59386e6#14",
        "-0.0",
        "-0.0127#5",
        "-0.018433#11",
        "-2.00#5",
        "-3.0820#10",
        "-0.874954#16",
        "-10288.29527676#38",
        "-9.2188#10",
        "-0.030048549#23",
        "-311.4521#19",
        "-0.0",
        "-1072.0#7",
        "-0.0009651#9",
        "-59159.52197#27",
        "-0.0",
        "-0.0000353#6",
        "-16.0#1"
    ]
);