Crates.io | malachite-base |
lib.rs | malachite-base |
version | 0.4.16 |
source | src |
created_at | 2022-06-04 22:33:39.903967 |
updated_at | 2024-09-05 05:01:01.43615 |
description | A collection of utilities, including new arithmetic traits and iterators that generate all values of a type |
homepage | https://malachite.rs/ |
repository | https://github.com/mhogrefe/malachite |
max_upload_size | |
id | 599934 |
size | 7,341,052 |
Rather than using this crate directly, use the
malachite
meta-crate. It re-exports all of this crate's
public members.
In malachite-base
's doctests you will frequently see import paths beginning with
malachite_base::
. When using the malachite
crate, replace this part of the paths with
malachite::
.
This crate contains many utilities that are used by the
malachite-nz
and
malachite-q
crates. These utilities include
CheckedAdd
.Gcd
,
FloorSqrt
,
and
BitAccess
.u32
s:
use malachite_base::num::exhaustive::exhaustive_unsigneds;
use malachite_base::tuples::exhaustive::exhaustive_pairs_from_single;
let mut pairs = exhaustive_pairs_from_single(exhaustive_unsigneds::<u32>());
assert_eq!(
pairs.take(20).collect::<Vec<_>>(),
&[
(0, 0), (0, 1), (1, 0), (1, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 0), (2, 1),
(3, 0), (3, 1), (2, 2), (2, 3), (3, 2), (3, 3), (0, 4), (0, 5), (1, 4), (1, 5)
]
);
RoundingMode
enum, which allows you to specify the rounding behavior of various functions.NiceFloat
wrapper, which provides alternative implementations of
Eq
,
Ord
, and
Display
for floating-point values which are in some ways nicer than the defaults.This crate comes with a bin
target that can be used for running demos and benchmarks.
mod_pow
function on u32
s, you can use the
following command:
cargo run --features bin_build --release -- -l 10000 -m exhaustive -d demo_mod_pow_u32
This command uses the exhaustive
mode, which generates every possible input, generally
starting with the simplest input and progressing to more complex ones. Another mode is
random
. The -l
flag specifies how many inputs should be generated.u64
s:
cargo run --features bin_build --release -- -l 1000000 -m random -b \
benchmark_gcd_algorithms_u64 -o gcd-bench.gp
This creates a file called gcd-bench.gp. You can use gnuplot to create an SVG from it like
so:
gnuplot -e "set terminal svg; l \"gcd-bench.gp\"" > gcd-bench.svg
The list of available demos and benchmarks is not documented anywhere; you must find them by
browsing through
bin_util/demo_and_bench
.
random
: This feature provides some functions for randomly generating values. It is off by
default to avoid pulling in some extra dependencies.test_build
: A large proportion of the code in this crate is only used for testing. For a
typical user, building this code would result in an unnecessarily long compilation time and
an unnecessarily large binary. Much of it is also used for testing
malachite-nz
and
malachite-q
, so it can't just be confined to the
tests
directory. My solution is to only build this code when the test_build
feature is
enabled. If you want to run unit tests, you must enable test_build
. However, doctests don't
require it, since they only test the public interface. Enabling this feature also enables
random
.bin_build
: This feature is used to build the code for demos and benchmarks, which also
takes a long time to build. Enabling this feature also enables test_build
and random
.Malachite is developed by Mikhail Hogrefe. Thanks to b4D8, florian1345, konstin, Rowan Hart, YunWon Jeong, Park Joon-Kyu, Antonio Mamić, OliverNChalk, and shekohex for additional contributions.
Copyright © 2024 Mikhail Hogrefe