Skip to content

Commit

Permalink
added Float multiplication and squaring
Browse files Browse the repository at this point in the history
  • Loading branch information
mhogrefe committed Jun 22, 2024
1 parent 7b1fb14 commit 4c80623
Show file tree
Hide file tree
Showing 115 changed files with 27,953 additions and 1,216 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ members = ['malachite', 'malachite-base', 'malachite-float', 'malachite-nz', 'ma
resolver = "2"

[workspace.dependencies]
malachite-base = { version = "0.4.13", path = 'malachite-base' }
malachite-nz = { version = "0.4.13", path = 'malachite-nz', default_features = false }
malachite-q = { version = "0.4.13", path = 'malachite-q' }
malachite-float = { version = "0.4.13", path = 'malachite-float' }
malachite-base = { version = "0.4.14", path = 'malachite-base' }
malachite-nz = { version = "0.4.14", path = 'malachite-nz', default_features = false }
malachite-q = { version = "0.4.14", path = 'malachite-q' }
malachite-float = { version = "0.4.14", path = 'malachite-float' }

[profile.release]
lto = "fat"
Expand Down
14 changes: 7 additions & 7 deletions additional-lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
('./malachite-nz/src/natural/arithmetic/mod.rs', 46),
('./malachite-nz/src/natural/arithmetic/mod.rs', 47),
('./malachite-nz/src/natural/arithmetic/mod.rs', 48),
('./malachite-nz/src/natural/arithmetic/mod.rs', 150),
('./malachite-nz/src/natural/arithmetic/mod.rs', 151),
('./malachite-nz/src/natural/arithmetic/mod.rs', 174),
('./malachite-nz/src/natural/arithmetic/mod.rs', 175),
('./malachite-nz/src/natural/arithmetic/mod.rs', 176),
('./malachite-nz/src/natural/arithmetic/mod.rs', 559),
('./malachite-nz/src/natural/arithmetic/mod.rs', 561),
('./malachite-nz/src/natural/arithmetic/mod.rs', 154),
('./malachite-nz/src/natural/arithmetic/mod.rs', 155),
('./malachite-nz/src/natural/arithmetic/mod.rs', 178),
('./malachite-nz/src/natural/arithmetic/mod.rs', 179),
('./malachite-nz/src/natural/arithmetic/mod.rs', 180),
('./malachite-nz/src/natural/arithmetic/mod.rs', 563),
('./malachite-nz/src/natural/arithmetic/mod.rs', 565),
('./malachite-nz/src/natural/conversion/digits/power_of_2_digit_iterable.rs', 528),
('./malachite-nz/src/natural/conversion/digits/power_of_2_digit_iterable.rs', 530),
('./malachite-nz/src/natural/conversion/digits/power_of_2_digit_iterable.rs', 833),
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ Malachite uses `no_std`, unless the `random`, `test_build`, or `bin_build` featu
To use Malachite, add the following to your project's `Cargo.toml` file:
```yaml
[dependencies.malachite]
version = "0.4.13"
version = "0.4.14"
```

By default, all of Malachite's features are included, but you can opt out of some of them. For
example, if you want to use `Natural` and `Integer` but not `Rational`, you can instead use
```yaml
[dependencies.malachite]
version = "0.4.13"
version = "0.4.14"
default-features = false
features = [ "naturals_and_integers" ]
```
Expand Down
2 changes: 1 addition & 1 deletion malachite-base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "malachite-base"
version = "0.4.13"
version = "0.4.14"
authors = ["Mikhail Hogrefe <[email protected]>"]
rust-version = "1.61.0"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion malachite-base/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use bin_util::generate::tuning_manager::{build_reference_data, test};
use malachite_base::test_util::runner::cmd::read_command_line_arguments;
#[cfg(feature = "bin_build")]
use malachite_base::test_util::runner::Runner;
#[cfg(feature = "bin_build")]

// Examples:
//
// ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ fn demo_root_assign_rem<T: PrimitiveUnsigned>(gm: GenMode, config: &GenConfig, l
macro_rules! benchmark_floor_cbrt_algorithms_unsigned {
($t:ident, $f:ident) => {
fn $f(gm: GenMode, config: &GenConfig, limit: usize, file_name: &str) {
#[allow(clippy::cast_lossless)]
run_benchmark(
&format!("{}.floor_root(3)", $t::NAME),
BenchmarkType::Algorithms,
Expand Down Expand Up @@ -583,6 +584,7 @@ fn benchmark_cbrt_assign_rem<T: PrimitiveUnsigned>(
macro_rules! benchmark_floor_root_algorithms_unsigned {
($t:ident, $f:ident) => {
fn $f(gm: GenMode, config: &GenConfig, limit: usize, file_name: &str) {
#[allow(clippy::cast_lossless)]
run_benchmark(
&format!("{}.floor_root(u64)", $t::NAME),
BenchmarkType::Algorithms,
Expand Down
55 changes: 53 additions & 2 deletions malachite-base/src/bools/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

use crate::num::arithmetic::traits::Parity;
use crate::num::random::geometric::SimpleRational;
use crate::num::random::{random_unsigneds_less_than, RandomUnsignedsLessThan};
use crate::num::random::{
random_unsigneds_less_than, RandomUnsignedsLessThan, VariableRangeGenerator,
};
use crate::random::Seed;
use rand::Rng;
use rand_chacha::ChaCha20Rng;
Expand Down Expand Up @@ -104,7 +106,11 @@ impl Iterator for WeightedRandomBools {
/// Panics if `p_denominator` is 0 or `p_numerator > p_denominator`.
///
/// # Expected complexity per iteration
/// Constant time and additional memory.
/// $T(n) = O(n)$
///
/// $M(n) = O(1)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ = `p_denominator.significant_bits()`.
///
/// # Examples
/// ```
Expand All @@ -129,3 +135,48 @@ pub fn weighted_random_bools(
xs: random_unsigneds_less_than(seed, p.d),
}
}

/// Generates a random [`bool`] with a particular probability of being `true`.
///
/// Let $n_p$ be `p_numerator`, $d_p$ be `p_denominator`, and let $p=n_p/d_p$. Then
///
/// $P(\text{true}) = p$,
///
/// $P(\text{false}) = 1-p$.
///
/// # Panics
/// Panics if `p_denominator` is 0 or `p_numerator > p_denominator`.
///
/// # Expected complexity
/// $T(n) = O(n)$
///
/// $M(n) = O(1)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ = `p_denominator.significant_bits()`.
///
/// # Examples
/// ```
/// use malachite_base::bools::random::get_weighted_random_bool;
/// use malachite_base::num::random::variable_range_generator;
/// use malachite_base::random::EXAMPLE_SEED;
///
/// assert_eq!(
/// get_weighted_random_bool(&mut variable_range_generator(EXAMPLE_SEED), 1, 10),
/// false
/// );
/// ```
pub fn get_weighted_random_bool(
range_generator: &mut VariableRangeGenerator,
p_numerator: u64,
p_denominator: u64,
) -> bool {
assert_ne!(p_denominator, 0);
assert!(p_numerator <= p_denominator);
if p_numerator == 0 {
return false;
} else if p_numerator == p_denominator {
return true;
}
let p = SimpleRational::new(p_numerator, p_denominator);
range_generator.next_less_than(p.d) < p.n
}
2 changes: 1 addition & 1 deletion malachite-base/src/chars/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub fn random_char_inclusive_range(seed: Seed, a: char, b: char) -> RandomCharRa
/// .take(20)
/// .collect::<String>()
/// .as_str(),
/// "𘋍𰜂礢깻ꅏ枂쭦𬝶╱𣑿⢍𰺟瀐\u{8d835}𲆽ՠ𦧹\u{37de9}\u{d71d4}𪂋"
/// "𘋈𰒏礝깶ꅊ杽쭡𬝱╱𣑺⢍𰰬瀋\u{8daa8}𱽊ՠ𦧴\u{3805c}\u{d7447}𪂆"
/// )
/// ```
#[inline]
Expand Down
10 changes: 5 additions & 5 deletions malachite-base/src/num/basic/floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,9 @@ macro_rules! impl_basic_traits_primitive_float {
) => {
impl PrimitiveFloat for $t {
const WIDTH: u64 = $width;
const MANTISSA_WIDTH: u64 = (core::$t::MANTISSA_DIGITS as u64) - 1;
const MANTISSA_WIDTH: u64 = ($t::MANTISSA_DIGITS as u64) - 1;

const MAX_FINITE: Self = core::$t::MAX;
const MAX_FINITE: Self = $t::MAX;
const MIN_POSITIVE_SUBNORMAL: Self = $min_positive_subnormal;
const MAX_SUBNORMAL: Self = $max_subnormal;
const MIN_POSITIVE_NORMAL: Self = $min_positive_normal;
Expand Down Expand Up @@ -683,17 +683,17 @@ macro_rules! impl_basic_traits_primitive_float {

/// The constant Infinity for primitive floating-point types.
impl Infinity for $t {
const INFINITY: $t = core::$t::INFINITY;
const INFINITY: $t = $t::INFINITY;
}

/// The constant -Infinity for primitive floating-point types.
impl NegativeInfinity for $t {
const NEGATIVE_INFINITY: $t = core::$t::NEG_INFINITY;
const NEGATIVE_INFINITY: $t = $t::NEG_INFINITY;
}

/// The constant NaN for primitive floating-point types.
impl NaN for $t {
const NAN: $t = core::$t::NAN;
const NAN: $t = $t::NAN;
}

/// The lowest value representable by this type, negative infinity.
Expand Down
4 changes: 2 additions & 2 deletions malachite-base/src/num/basic/integers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ macro_rules! impl_basic_traits_primitive_int {
/// # Examples
/// See [here](self).
impl Min for $t {
const MIN: $t = core::$t::MIN;
const MIN: $t = $t::MIN;
}

/// The highest value representable by this type.
Expand All @@ -1059,7 +1059,7 @@ macro_rules! impl_basic_traits_primitive_int {
/// # Examples
/// See [here](self).
impl Max for $t {
const MAX: $t = core::$t::MAX;
const MAX: $t = $t::MAX;
}
};
}
Expand Down
Loading

0 comments on commit 4c80623

Please sign in to comment.