Skip to main content

Crate malachite_float

Crate malachite_float 

Source
Expand description

This crate defines Floats, which are arbitrary-precision floating-point numbers.

Floats are not yet feature-complete, but the functions that are implemented are thoroughly tested and documented.

§Complexity conventions

Functions in this crate are documented with worst-case time and additional-memory bounds, following the conventions described in the malachite-base docs.

§Demos and benchmarks

This crate comes with a bin target that can be used for running demos and benchmarks.

  • Almost all of the public functions in this crate have an associated demo. Running a demo shows you a function’s behavior on a large number of inputs. For example, to demo Float addition, you can use the following command:
    cargo run --features bin_build --release -- -l 10000 -m exhaustive -d demo_float_add
    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.
  • You can use a similar command to run benchmarks. The following command benchmarks various Float addition implementations:
    cargo run --features bin_build --release -- -l 1000000 -m random -b \
        benchmark_float_add_algorithms -o add-bench.gp
    This creates a file called add-bench.gp. You can use gnuplot to create an SVG from it like so:
    gnuplot -e "set terminal svg; l \"add-bench.gp\"" > add-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.

§Features

  • 32_bit_limbs: Sets the type of Limb to u32 instead of the default, u64.
  • 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. 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.
  • 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.

Re-exports§

pub use float::ComparableFloat;
pub use float::ComparableFloatRef;
pub use float::Float;

Modules§

float
Float, the crate’s floating-point type, and everything defined on it.

Functions§

test_overflow
Given the (Float, Ordering) result of an operation, determines whether an overflow occurred.
test_underflow
Given the (Float, Ordering) result of an operation, determines whether an underflow occurred.