dashu-base 0.6.0-rc.4

Common trait definitions, error types, and utilities shared by the dashu math crates (integers, floats, rationals, and complex numbers). Defines the core abstractions the library builds on — Approximation, AbsOrd, Signed, SquareRoot, CubicRoot, EstimatedLog2, BitTest, and FloatEncoding — plus the Sign type and conversion errors.
Documentation

dashu-base

Common trait definitions for the dashu mathematics crates. See Docs.rs for the full documentation.

Quick example

The traits are implemented on primitive integers and on every dashu big-number type alike, so generic numeric code works across the whole library:

use dashu_base::{DivRem, ExtendedGcd, Gcd};
use dashu_int::UBig;

// ...on primitive integers
assert_eq!(12u8.gcd(10u8), 2u8);
let (q, r) = 17u8.div_rem(5u8);
assert_eq!((q, r), (3u8, 2u8));

// ...and on every dashu big-number type (UBig, FBig, RBig, ...)
assert_eq!(UBig::from(12u8).gcd(UBig::from(10u8)), UBig::from(2u8));
let (q, r) = UBig::from(17u8).div_rem(UBig::from(5u8));
assert_eq!((q, r), (UBig::from(3u8), UBig::from(2u8)));

// ExtendedGcd also returns the Bézout coefficients
let (g, x, y) = 12u8.gcd_ext(10u8);
assert_eq!(g, 2u8);
assert_eq!(g as i8, 12 * x + 10 * y); // 2 = 12·1 + 10·(-1)

License

See the top-level readme.