View on GitHub

malachite

An arbitrary-precision arithmetic library for Rust.

How Malachite Is Tested: Floats

This page lists every public function of Float, the arbitrary-precision binary floating-point type of the malachite-float crate, and records which independent implementations it is checked against. The introduction describes the oracles and the testing they sit in; this page is the ledger. It follows the organization of the crate’s documentation, one section per module, so that a function is where its documentation is.

Reading the tables

Each row is one operation, named after the module that implements it and linked to that module’s documentation. The Functions column lists the traits and methods the module implements. A trait’s by-value and by-reference implementations, its *Assign form, and the _prec, _round, and _prec_round variants of an operation (which differ only in the output precision and the rounding mode) count as one function, while functions with genuinely different results are listed separately. The oracles differ from those of the integer pages: FLINT and num have no arbitrary-precision binary floats, and GMP’s role is taken by MPFR, the reference implementation of correctly rounded arbitrary-precision arithmetic, through the rug crate.

  meaning
✓ The oracle computes this function and agrees with Malachite on every input tried.
≈ The oracle agrees, after an adaptation on the oracle side that is more than a change of spelling.
  The oracle does not check this function.

Azurite’s AzFloat has an unbounded exponent, while a Float’s exponent is bounded, so the Azurite oracle applies Malachite’s documented overflow and underflow rules to Azurite’s result before comparing; that adaptation is the same for every operation and is not counted as ≈. A function with no mark in any column is checked only by Malachite’s own unit and property tests; those rows are collected in What is not yet cross-checked. The internal ExtendedFloat type, which carries a wider exponent through intermediate computations, is not listed.

Basic

The constants, the classification predicates, and the accessors of the type itself, from malachite_float::float::basic.

Operation Functions Azurite MPFR Reference
constants Zero, One, Two, NegativeOne, OneHalf, NegativeZero, NaN, Infinity, NegativeInfinity, Min, Max   ✓  
constants one_prec, two_prec ✓ ✓  
constants negative_one_prec, one_half_prec   ✓  
constants min_positive_value_prec ✓ ✓  
constants max_finite_value_with_prec ✓    
constants abs_is_min_positive_value, abs_is_max_finite_value_with_prec      
default Default      
named Named      
clone Clone   ✓  
classification is_nan, is_finite, is_infinite, is_zero, is_normal ✓ ✓  
classification is_positive_zero, is_negative_zero, is_sign_positive, is_sign_negative, classify   ✓  
classification to_non_nan, into_non_nan, to_finite, into_finite      
get_and_set get_prec, get_exponent ✓ ✓  
get_and_set to_significand, into_significand, significand_ref ✓ ✓  
get_and_set get_min_prec      
get_and_set set_prec, set_prec_round ✓ ✓  
get_and_set from_float_prec, from_float_prec_round, and their _ref forms      
ulp ulp ✓    
ulp increment, decrement      
complexity complexity, SignificantBits      
can_round can_round   ✓  
subnormalize subnormalize, subnormalize_assign, subnormalize_ref   ✓  

The special values and the constants at a given precision are checked against MPFR’s, and Azurite checks one_prec, two_prec, and the extreme values min_positive_value_prec and max_finite_value_with_prec (built in Azurite from Malachite’s documented exponent range). The classification predicates are checked against MPFR’s, and the ones that do not depend on the sign of a zero also against Azurite’s. The precision, exponent, and significand accessors, and set_prec and set_prec_round (rounding to a new precision), are checked by Azurite and MPFR; ulp by Azurite. can_round, which decides whether an approximation with a known error bound can be rounded correctly to a target precision, is checked against MPFR’s mpfr_can_round, and subnormalize, which emulates an IEEE 754 format’s subnormal range, against mpfr_subnormalize. increment, decrement, get_min_prec, complexity, and the from_float_prec constructors, which compute the same thing as set_prec_round on a new value, are covered by property tests alone.

Comparison

From malachite_float::float::comparison. Float’s own comparison follows IEEE 754: NaN is unordered and 0.0 == -0.0. The wrapper ComparableFloat gives the total order and equality used for hashing and sorting, under which NaN equals itself and the two zeros differ.

Operation Functions Azurite MPFR Reference
cmp PartialOrd for Float ✓ ✓  
cmp Ord, PartialOrd for ComparableFloat ✓    
eq PartialEq for Float ✓ ✓  
eq PartialEq, Eq for ComparableFloat ✓    
hash Hash for ComparableFloat      
cmp_abs PartialOrdAbs for Float   ✓  
cmp_abs OrdAbs, PartialOrdAbs for ComparableFloat      
cmp_abs PartialOrdAbsDouble      
eq_abs EqAbs for Float and ComparableFloat      
min_max min, max, and their _prec, _round, and _prec_round forms   ✓  
min_max min_rational, max_rational, and their _prec, _round, and _prec_round forms      
min_max primitive_float_min_rational, primitive_float_max_rational      
partial_cmp_natural PartialOrd<Natural> and the reverse direction   ✓  
partial_cmp_integer PartialOrd<Integer> and the reverse direction   ✓  
partial_cmp_rational PartialOrd<Rational> and the reverse direction   ✓ ✓
partial_eq_natural PartialEq<Natural> and the reverse direction   ✓  
partial_eq_integer PartialEq<Integer> and the reverse direction   ✓  
partial_eq_rational PartialEq<Rational> and the reverse direction   ✓  
partial_cmp_primitive_int PartialOrd<u8>, …, PartialOrd<isize>, and the reverse directions   ✓  
partial_eq_primitive_int PartialEq<u8>, …, PartialEq<isize>, and the reverse directions   ✓  
partial_cmp_primitive_float PartialOrd<f32>, PartialOrd<f64>, and the reverse directions   ✓  
partial_eq_primitive_float PartialEq<f32>, PartialEq<f64>, and the reverse directions   ✓  
partial_cmp_abs_natural PartialOrdAbs<Natural> and the reverse direction   ✓  
partial_cmp_abs_integer PartialOrdAbs<Integer> and the reverse direction   ✓  
partial_cmp_abs_rational PartialOrdAbs<Rational> and the reverse direction   ✓  
partial_cmp_abs_primitive_int PartialOrdAbs<u8>, …, PartialOrdAbs<isize>, and the reverse directions   ✓  
partial_cmp_abs_primitive_float PartialOrdAbs<f32>, PartialOrdAbs<f64>, and the reverse directions      
eq_abs_natural EqAbs<Natural>, EqAbs<Integer>, EqAbs<Rational>, and the reverse directions      
eq_abs_primitive_int EqAbs with the primitive integers and floats, and the reverse directions      
partial_eq_gaussian_integer PartialEq<GaussianInteger>, PartialEq<GaussianRational>, and the reverse directions      
partial_cmp_abs_gaussian_integer PartialOrdAbs and EqAbs with GaussianInteger and GaussianRational, and the reverse directions      

Float’s comparison and equality are checked by Azurite and MPFR; ComparableFloat’s total order and equality by Azurite, which reads the sign of a zero from the printed value. Comparison and equality with a Natural, an Integer, a Rational, a primitive integer, or a primitive float are checked against MPFR (comparison with a Rational also against a reference that compares exponents first and converts the Float to a Rational exactly only when they tie). Azurite checks the comparisons and equalities with a Natural or an Integer with the Float on the left, but not the reverse direction, so those rows carry no Azurite mark. min and max, which round their result to a precision, are checked against MPFR’s mpfr_min and mpfr_max; MPFR has no comparison of absolute values with a Natural, an Integer, a Rational, or a primitive integer, and those are checked against MPFR’s comparison of the absolute values. The absolute-value comparisons with floats, the absolute-value equalities, the comparisons with Gaussian integers and rationals, the Rational forms of min and max, and partial_cmp_abs_double are covered by property tests alone.

Constants

From malachite_float::float::constants. Each constant is computed to any precision and rounded in any mode, and the returned Ordering says which way it was rounded.

Operation Functions Azurite MPFR Reference
catalans_constant catalans_constant_prec, catalans_constant_prec_round   ✓  
cbrt_2 cbrt_2_prec, cbrt_2_prec_round   ✓  
champernowne_constant champernowne_constant_prec, champernowne_constant_prec_round, champernowne_constant_base_prec, champernowne_constant_base_prec_round     ✓
champernowne_constant primitive_float_champernowne_constant_base      
copeland_erdos_constant copeland_erdos_constant_prec, copeland_erdos_constant_prec_round, copeland_erdos_constant_base_prec, copeland_erdos_constant_base_prec_round     ✓
copeland_erdos_constant primitive_float_copeland_erdos_constant_base      
dottie_number dottie_number_prec, dottie_number_prec_round      
e e_prec, e_prec_round   ✓  
eulers_constant eulers_constant_prec, eulers_constant_prec_round   ✓  
gauss_constant gauss_constant_prec, gauss_constant_prec_round      
gelfond_schneider_constant gelfond_schneider_constant_prec, gelfond_schneider_constant_prec_round      
gelfonds_constant gelfonds_constant_prec, gelfonds_constant_prec_round      
lemniscate_constant lemniscate_constant_prec, lemniscate_constant_prec_round     ✓
liouvilles_constant liouvilles_constant_prec, liouvilles_constant_prec_round, liouvilles_constant_base_prec, liouvilles_constant_base_prec_round     ✓
liouvilles_constant primitive_float_liouvilles_constant_base      
ln_10 ln_10_prec, ln_10_prec_round   ✓  
ln_2 ln_2_prec, ln_2_prec_round   ✓  
log_10_2 log_10_2_prec, log_10_2_prec_round   ✓  
log_10_e log_10_e_prec, log_10_e_prec_round     ✓
log_2_10 log_2_10_prec, log_2_10_prec_round   ✓  
log_2_e log_2_e_prec, log_2_e_prec_round     ✓
one_over_pi one_over_pi_prec, one_over_pi_prec_round     ✓
one_over_sqrt_pi one_over_sqrt_pi_prec, one_over_sqrt_pi_prec_round     ✓
one_over_sqrt_tau one_over_sqrt_tau_prec, one_over_sqrt_tau_prec_round     ✓
phi phi_prec, phi_prec_round ✓    
pi pi_prec, pi_prec_round   ✓  
pi_over_2 pi_over_2_prec, pi_over_2_prec_round      
pi_over_3 pi_over_3_prec, pi_over_3_prec_round     ✓
pi_over_4 pi_over_4_prec, pi_over_4_prec_round      
pi_over_6 pi_over_6_prec, pi_over_6_prec_round      
pi_over_8 pi_over_8_prec, pi_over_8_prec_round      
prime_constant prime_constant_prec, prime_constant_prec_round ✓    
prouhet_thue_morse_constant prouhet_thue_morse_constant_prec, prouhet_thue_morse_constant_prec_round ✓   ✓
ramanujans_constant ramanujans_constant_prec, ramanujans_constant_prec_round      
sqrt_2 sqrt_2_prec, sqrt_2_prec_round ✓ ✓  
sqrt_2_over_2 sqrt_2_over_2_prec, sqrt_2_over_2_prec_round ✓ ✓  
sqrt_3 sqrt_3_prec, sqrt_3_prec_round ✓ ✓  
sqrt_3_over_3 sqrt_3_over_3_prec, sqrt_3_over_3_prec_round ✓ ✓  
sqrt_5 sqrt_5_prec, sqrt_5_prec_round ✓ ✓  
sqrt_5_over_5 sqrt_5_over_5_prec, sqrt_5_over_5_prec_round ✓ ✓  
sqrt_pi sqrt_pi_prec, sqrt_pi_prec_round     ✓
tau tau_prec, tau_prec_round      
two_over_pi two_over_pi_prec, two_over_pi_prec_round      
two_over_sqrt_pi two_over_sqrt_pi_prec, two_over_sqrt_pi_prec_round      

The fifteen constants that MPFR provides directly or computes as a correctly rounded value of one of its functions (\(\pi\), \(e\), Euler’s and Catalan’s constants, \(\ln 2\), \(\ln 10\), \(\log_{10} 2\), \(\log_2 10\), and the square and cube roots) are compared with MPFR at every precision and rounding mode the tests generate. Twelve more are checked against references: the digit-defined constants (Champernowne’s, Copeland–Erdős, and Liouville’s, in any base, and the Prouhet–Thue–Morse constant) against a digit-by-digit expansion bracketed by exact Rationals, and the constants built from others (\(1/\pi\), \(\pi/3\), \(\sqrt{\pi}\), the lemniscate constant, \(\log_2 e\), and the like) against a computation that brackets the inputs at a higher precision and rounds once the bracket decides the result. Every constant, those with no oracle included, is also compared with a hard-coded value at precisions 1,000 and 10,000, and its rounding Orderings are checked against its neighbors: the Floor and Ceiling results must be adjacent, with the exact value between them. The constants that are \(\pi\) or \(\tau\) times a power of 2 (\(\pi/2\), \(\pi/4\), \(\pi/8\), \(\tau\)) are exact shifts of a checked value; \(\pi/6\), \(2/\pi\), \(2/\sqrt{\pi}\), the Dottie number, Gauss’s constant, Gelfond’s and the Gelfond–Schneider constants, and Ramanujan’s constant rely on those hard-coded values and their property tests. Nine constants are also checked against Azurite (AzFloat.sqrt2PrecRound and its siblings) at every precision and rounding mode the demos generate, up to precision 10,000: \(\sqrt2\), \(\sqrt3\), \(\sqrt5\), \(\sqrt2/2\), \(\sqrt3/3\), \(\sqrt5/5\), \(\phi\), the prime constant, and the Prouhet–Thue–Morse constant. For \(\phi\) and the prime constant, Azurite is the only oracle.

Arithmetic

From malachite_float::float::arithmetic. The module is large, so its rows are grouped by theme.

Addition, subtraction, multiplication, and division

Operation Functions Azurite MPFR Reference
add Add, add_prec_round ✓ ✓ ✓
add add_rational_prec_round ✓ ✓ ✓
sub Sub, sub_prec_round ✓ ✓ ✓
sub sub_rational_prec_round ✓ ✓ ✓
mul Mul, mul_prec_round ✓ ✓ ✓
mul mul_rational_prec_round ✓ ✓ ✓
div Div, div_prec_round ✓ ✓ ✓
div div_rational_prec_round ✓ ✓ ✓
div rational_div_float_prec_round ✓ ✓ ✓
neg Neg ✓ ✓  
abs Abs ✓ ✓  
abs abs_negative_zero      
reciprocal Reciprocal, reciprocal_prec_round   ✓ ✓
square Square, square_prec_round ✓ ✓ ✓
abs_squared AbsSquared      
sum Sum, sum_prec_round   ✓  
sum primitive_float_sum      
product Product, product_prec_round      
product primitive_float_product      
dot dot_prec_round   ✓  
dot primitive_float_dot      
add_mul AddMul, add_mul_prec_round   ✓ ✓
add_mul add_mul_rational_prec_round     ✓
add_mul primitive_float_add_mul, primitive_float_add_mul_rational      
sub_mul SubMul, sub_mul_prec_round   ✓ ✓
sub_mul sub_mul_rational_prec_round     ✓
sub_mul primitive_float_sub_mul, primitive_float_sub_mul_rational      
mul_add_mul MulAddMul, mul_add_mul_prec_round   ✓ ✓
mul_add_mul mul_add_mul_rational_prec_round     ✓
mul_add_mul primitive_float_mul_add_mul, primitive_float_mul_add_mul_rational      
mul_sub_mul MulSubMul, mul_sub_mul_prec_round   ✓ ✓
mul_sub_mul mul_sub_mul_rational_prec_round     ✓
mul_sub_mul primitive_float_mul_sub_mul, primitive_float_mul_sub_mul_rational      
average Average, average_prec_round      
positive_difference positive_difference_prec_round   ✓  
positive_difference positive_difference_rational_prec_round      
positive_difference rational_positive_difference_float_prec_round      
positive_difference primitive_float_positive_difference, primitive_float_positive_difference_rational, primitive_float_rational_positive_difference_float      
hypot Hypot, hypot_prec_round   ✓  
hypot primitive_float_hypot      

Most operations come in several input forms, each its own row: two Floats; a Float and a Rational, which is used exactly rather than rounded first; and, for the primitive_float_* functions, f32 or f64 inputs with a correctly rounded f32 or f64 result. The four field operations, squaring, negation, and absolute value are checked by Azurite (AzFloat.addPrecRound and its siblings) and MPFR, and the four operations and squaring also against references that compute the exact result as a Rational and round it once. MPFR’s operations with a rational operand are exact before their single rounding, so the Rational forms of the four operations are compared with them directly; they are also checked by Azurite (AzFloat.addRatPrecRound, subRatPrecRound, mulRatPrecRound, divRatPrecRound, ratSubPrecRound, and ratDivPrecRound), including Rational + Float, Rational - Float, Rational * Float, and Rational / Float. Some of the demos on extreme inputs (those for addition and subtraction, and the _round and _prec_round forms of multiplication and division) take a fiftieth to a tenth of a second per line, so they are checked on 300 lines in each generator mode rather than 10,000. Sums, dot products, hypot, positive_difference (MPFR’s mpfr_dim), and the fused operations (MPFR’s mpfr_fma and mpfr_fmma families) are checked against MPFR, and the fused operations’ Rational forms against exact references. product, average, abs_squared, abs_negative_zero, the Rational form of positive_difference, and the primitive_float_* versions in this section are covered by property tests, which compare the primitive versions with the Float functions at the primitive type’s precision and exponent range.

Shifts and powers of 2

Operation Functions Azurite MPFR Reference
shl Shl ✓ ✓ ✓
shr Shr ✓ ✓ ✓
shl_round ShlRound, shl_prec_round   ✓ ✓
shr_round ShrRound, shr_prec_round   ✓ ✓
power_of_2 PowerOf2, power_of_2_prec_round ✓ ✓ ✓
is_power_of_2 IsPowerOf2 ✓    

Shifts multiply by a power of 2 and change only the exponent; they are checked by Azurite and MPFR, and against a reference that shifts the exact Rational value. shl_round and shr_round, which also round to a new precision, are checked against MPFR and similar references. power_of_2 is checked by Azurite, MPFR, and references for every exponent type, and is_power_of_2 by Azurite.

Signs and units

Operation Functions Azurite MPFR Reference
sign Sign ✓    
is_unit IsUnit      
conjugate Conjugate      
canonicalize_unit CanonicalizeUnit      
canonical_unit_i_pow CanonicalUnitIPow      

sign is checked by Azurite. The unit functions are the trivial cases of functions that matter for Gaussian numbers and polynomials, where they are cross-checked.

Rounding

Operation Functions Azurite MPFR Reference
round_to_integer round_to_integer_prec_round   ✓  
round_to_integer round_to_integer_then_prec_round   ✓  
round_to_integer round_to_integer_ties_away      
round_to_integer round_to_integer_ties_away_then_prec_round      
round_to_integer primitive_float_round_to_integer, primitive_float_round_to_integer_ties_away      
fractional_part fractional_part_prec_round   ✓  
fractional_part integer_and_fractional_parts_prec_round   ✓  
fractional_part primitive_float_fractional_part, primitive_float_integer_and_fractional_parts      
rem Rem, rem_prec_round   ✓  
rem ieee_remainder_prec_round   ✓  
rem ieee_remainder_and_quotient_bits_prec_round   ✓  
rem ieee_remainder_rational_prec_round      
rem ieee_remainder_rational_and_quotient_bits_prec_round      
rem rational_ieee_remainder_float_prec_round      
rem rational_ieee_remainder_float_and_quotient_bits_prec_round      
rem rational_rem_float_prec_round      
rem rational_rem_float_and_quotient_bits_prec_round      
rem rem_and_quotient_bits_prec_round   ✓  
rem rem_rational_prec_round      
rem rem_rational_and_quotient_bits_prec_round      
rem rem_unsigned_prec_round   ✓  
rem primitive_float_ieee_remainder, primitive_float_ieee_remainder_and_quotient_bits, primitive_float_ieee_remainder_rational, primitive_float_ieee_remainder_rational_and_quotient_bits, primitive_float_rational_ieee_remainder_float, primitive_float_rational_rem_float, primitive_float_rem, primitive_float_rem_and_quotient_bits, primitive_float_rem_rational, primitive_float_rem_rational_and_quotient_bits, primitive_float_rem_unsigned      

Rounding to an integer, including the forms that round the integer again to a target precision (round_to_integer_then), is checked against MPFR’s rounding functions, called directly; the forms that break ties away from zero are covered by property tests. The fractional part and the split into integer and fractional parts are checked against MPFR’s mpfr_frac and mpfr_modf. The remainders are checked against MPFR’s truncated and IEEE 754 remainders, and the versions that also return the low bits of the quotient against mpfr_fmodquo and mpfr_remquo; the forms with a Rational operand on either side have no MPFR counterpart and are covered by property tests.

Roots and powers

Operation Functions Azurite MPFR Reference
sqrt Sqrt, sqrt_prec_round ✓ ✓  
sqrt sqrt_rational_prec_round     ✓
sqrt sqrt_unsigned_prec_round      
sqrt primitive_float_sqrt_rational      
reciprocal_sqrt ReciprocalSqrt, reciprocal_sqrt_prec_round ✓ ✓  
reciprocal_sqrt reciprocal_sqrt_rational_prec_round     ✓
reciprocal_sqrt primitive_float_reciprocal_sqrt, primitive_float_reciprocal_sqrt_rational      
cbrt Cbrt, cbrt_prec_round   ✓  
cbrt cbrt_rational_prec_round      
cbrt primitive_float_cbrt, primitive_float_cbrt_rational      
root Root<i64>, root_s_prec_round   ✓  
root root_s_rational_prec_round      
root Root<u64>, root_u_prec_round   ✓  
root root_u_rational_prec_round      
root primitive_float_root_s, primitive_float_root_s_rational, primitive_float_root_u, primitive_float_root_u_rational      
pow Pow, pow_prec_round   ✓  
pow pow_integer_prec_round   ✓  
pow pow_rational_prec_round      
pow pow_s_prec_round   ✓  
pow pow_u_prec_round   ✓  
pow powr_prec_round      
pow rational_pow_prec_round      
pow rational_pow_rational_prec_round      
pow unsigned_pow_prec_round   ✓  
pow unsigned_pow_rational_prec_round   ≈  
pow unsigned_pow_unsigned_prec_round   ✓  
pow primitive_float_pow, primitive_float_pow_integer, primitive_float_pow_rational, primitive_float_pow_u, primitive_float_rational_pow, primitive_float_unsigned_pow      
compound Compound, compound_prec_round   ✓  
compound primitive_float_compound      
agm Agm, agm_prec_round   ✓  
agm agm_rational_prec_round      
agm primitive_float_agm, primitive_float_agm_rational      

The square root, reciprocal square root, cube root, and roots with a u64 or i64 index are checked against MPFR (mpfr_sqrt, mpfr_rec_sqrt, mpfr_cbrt, mpfr_rootn_ui, and mpfr_rootn_si), and the square root and reciprocal square root also by Azurite; their Rational forms are checked against references that use an exact root when there is one and bracket the result otherwise. Powers with a Float, Integer, u64, or i64 exponent, and the powers of an unsigned base, are checked against MPFR’s mpfr_pow and mpfr_pow_z; compound, \((1 + x)^n\), against mpfr_compound_si; and the arithmetic-geometric mean against mpfr_agm. An unsigned base raised to a Rational is ≈: MPFR has no such function, so the oracle brackets the result with MPFR’s exp and ln at increasing precision until its rounding is decided. powr, the powers with a Rational base or with a Float base and a Rational exponent, the Rational forms of agm and the roots, and the primitive_float_* versions are covered by property tests.

Exponentials and logarithms

Operation Functions Azurite MPFR Reference
exp Exp, exp_prec_round   ✓  
exp exp_rational_prec_round   ≈  
exp primitive_float_exp, primitive_float_exp_rational      
exp_x_minus_1 ExpXMinus1, exp_x_minus_1_prec_round   ✓  
exp_x_minus_1 exp_x_minus_1_rational_prec_round   ≈  
exp_x_minus_1 primitive_float_exp_x_minus_1, primitive_float_exp_x_minus_1_rational      
power_of_2_of_float PowerOf2, power_of_2_of_float_prec_round   ✓  
power_of_2_of_float power_of_2_rational_prec_round   ≈  
power_of_2_of_float primitive_float_power_of_2, primitive_float_power_of_2_rational      
power_of_2_x_minus_1 PowerOf2XMinus1, power_of_2_x_minus_1_prec_round   ✓  
power_of_2_x_minus_1 power_of_2_x_minus_1_rational_prec_round   ≈  
power_of_2_x_minus_1 primitive_float_power_of_2_x_minus_1, primitive_float_power_of_2_x_minus_1_rational      
power_of_10 PowerOf10, power_of_10_of_float_prec_round   ✓  
power_of_10 power_of_10_rational_prec_round   ≈  
power_of_10 primitive_float_power_of_10, primitive_float_power_of_10_rational      
power_of_10_x_minus_1 PowerOf10XMinus1, power_of_10_x_minus_1_prec_round   ✓  
power_of_10_x_minus_1 power_of_10_x_minus_1_rational_prec_round   ≈  
power_of_10_x_minus_1 primitive_float_power_of_10_x_minus_1, primitive_float_power_of_10_x_minus_1_rational      
ln Ln, ln_prec_round   ✓  
ln ln_rational_prec_round      
ln ln_unsigned_prec_round      
ln primitive_float_ln, primitive_float_ln_rational      
ln_1_plus_x Ln1PlusX, ln_1_plus_x_prec_round   ✓  
ln_1_plus_x primitive_float_ln_1_plus_x      
log_base_2 LogBase2, log_base_2_prec_round   ✓  
log_base_2 log_base_2_rational_prec_round   ≈  
log_base_2 primitive_float_log_base_2, primitive_float_log_base_2_rational      
log_base_2_1_plus_x LogBase2Of1PlusX, log_base_2_1_plus_x_prec_round   ✓  
log_base_2_1_plus_x primitive_float_log_base_2_1_plus_x      
log_base_10 LogBase10, log_base_10_prec_round   ✓  
log_base_10 log_base_10_rational_prec_round   ≈  
log_base_10 primitive_float_log_base_10, primitive_float_log_base_10_rational      
log_base_10_1_plus_x LogBase10Of1PlusX, log_base_10_1_plus_x_prec_round   ✓  
log_base_10_1_plus_x primitive_float_log_base_10_1_plus_x      
log_base LogBase, log_base_prec_round   ≈  
log_base log_base_rational_prec_round   ≈  
log_base primitive_float_log_base, primitive_float_log_base_rational      
log_base_1_plus_x LogBaseOf1PlusX, log_base_1_plus_x_prec_round   ≈  
log_base_1_plus_x primitive_float_log_base_1_plus_x      
log_base_power_of_2 LogBasePowerOf2, log_base_power_of_2_prec_round   ≈  
log_base_power_of_2 log_base_power_of_2_rational_prec_round   ≈  
log_base_power_of_2 primitive_float_log_base_power_of_2, primitive_float_log_base_power_of_2_rational      
log_base_power_of_2_1_plus_x LogBasePowerOf2Of1PlusX, log_base_power_of_2_1_plus_x_prec_round   ≈  
log_base_power_of_2_1_plus_x primitive_float_log_base_power_of_2_1_plus_x      
log_base_float_base LogBase, log_base_float_base_prec_round   ≈  
log_base_float_base primitive_float_log_base_float_base      
log_base_float_base_1_plus_x LogBaseOf1PlusX, log_base_float_base_1_plus_x_prec_round   ≈  
log_base_float_base_1_plus_x primitive_float_log_base_float_base_1_plus_x      
log_base_rational_base LogBase, log_base_rational_base_prec_round   ≈  
log_base_rational_base primitive_float_log_base_rational_base      
log_base_rational_base_1_plus_x LogBaseOf1PlusX, log_base_rational_base_1_plus_x_prec_round   ≈  
log_base_rational_base_1_plus_x primitive_float_log_base_rational_base_1_plus_x      
log_base_rational_float_base log_base_rational_float_base_prec_round   ≈  
log_base_rational_float_base primitive_float_log_base_rational_float_base      
log_base_rational_rational_base log_base_rational_rational_base_prec_round   ≈  
log_base_rational_rational_base primitive_float_log_base_rational_rational_base      

The exponentials and the logarithms to bases 2, \(e\), and 10, with and without the \(x - 1\) and \(1 + x\) forms, are checked against the corresponding MPFR functions. The logarithms to other bases (a u64, a power of 2, a Float, or a Rational) are ≈: MPFR has no such functions, so the oracle brackets the quotient of two MPFR logarithms at increasing precision until its rounding is decided, and recognizes the exactly representable results directly. The Rational forms are ≈ for the reason given under Trigonometric functions; ln_rational and ln_unsigned are covered by property tests, and the primitive_float_* versions are compared with the Float functions.

Trigonometric functions

Operation Functions Azurite MPFR Reference
sin Sin, sin_prec_round   ✓  
sin sin_pi_prec_round   ✓  
sin sin_pi_rational_prec_round      
sin sin_rational_prec_round   ≈  
sin sin_with_period_prec_round   ✓  
sin sin_with_period_rational_prec_round   ≈  
sin primitive_float_sin, primitive_float_sin_rational, primitive_float_sin_with_period, primitive_float_sin_with_period_rational   ≈  
sin primitive_float_sin_pi, primitive_float_sin_pi_rational      
cos Cos, cos_prec_round   ✓  
cos cos_pi_prec_round   ✓  
cos cos_pi_rational_prec_round      
cos cos_rational_prec_round   ≈  
cos cos_with_period_prec_round   ✓  
cos cos_with_period_rational_prec_round   ≈  
cos primitive_float_cos, primitive_float_cos_rational, primitive_float_cos_with_period, primitive_float_cos_with_period_rational   ≈  
cos primitive_float_cos_pi, primitive_float_cos_pi_rational      
tan Tan, tan_prec_round   ✓  
tan tan_pi_prec_round   ✓  
tan tan_pi_rational_prec_round      
tan tan_rational_prec_round   ≈  
tan tan_with_period_prec_round   ✓  
tan tan_with_period_rational_prec_round   ≈  
tan primitive_float_tan, primitive_float_tan_rational, primitive_float_tan_with_period, primitive_float_tan_with_period_rational   ≈  
tan primitive_float_tan_pi, primitive_float_tan_pi_rational      
sec Sec, sec_prec_round   ✓  
sec sec_pi_prec_round     ✓
sec sec_pi_rational_prec_round      
sec sec_rational_prec_round   ≈  
sec sec_with_period_prec_round     ✓
sec sec_with_period_rational_prec_round     ✓
sec primitive_float_sec, primitive_float_sec_rational   ≈  
sec primitive_float_sec_pi, primitive_float_sec_pi_rational, primitive_float_sec_with_period, primitive_float_sec_with_period_rational      
csc Csc, csc_prec_round   ✓  
csc csc_pi_prec_round     ✓
csc csc_pi_rational_prec_round      
csc csc_rational_prec_round   ≈  
csc csc_with_period_prec_round     ✓
csc csc_with_period_rational_prec_round     ✓
csc primitive_float_csc, primitive_float_csc_rational   ≈  
csc primitive_float_csc_pi, primitive_float_csc_pi_rational, primitive_float_csc_with_period, primitive_float_csc_with_period_rational      
cot Cot, cot_prec_round   ✓  
cot cot_pi_prec_round     ✓
cot cot_pi_rational_prec_round      
cot cot_rational_prec_round   ≈  
cot cot_with_period_prec_round     ✓
cot cot_with_period_rational_prec_round     ✓
cot primitive_float_cot, primitive_float_cot_rational   ≈  
cot primitive_float_cot_pi, primitive_float_cot_pi_rational, primitive_float_cot_with_period, primitive_float_cot_with_period_rational      
sin_cos SinCos, sin_cos_prec_round   ✓  
sin_cos sin_cos_pi_prec_round   ✓  
sin_cos sin_cos_pi_rational_prec_round   ≈  
sin_cos sin_cos_rational_prec_round   ≈  
sin_cos sin_cos_with_period_prec_round   ✓  
sin_cos sin_cos_with_period_rational_prec_round   ≈  
sin_cos primitive_float_sin_cos, primitive_float_sin_cos_pi, primitive_float_sin_cos_pi_rational, primitive_float_sin_cos_rational, primitive_float_sin_cos_with_period, primitive_float_sin_cos_with_period_rational      
asin Asin, asin_prec_round   ✓  
asin asin_pi_prec_round   ✓  
asin asin_pi_rational_prec_round   ≈  
asin asin_rational_prec_round   ≈  
asin asin_with_period_prec_round   ✓  
asin asin_with_period_rational_prec_round   ≈  
asin primitive_float_asin, primitive_float_asin_pi, primitive_float_asin_pi_rational, primitive_float_asin_rational, primitive_float_asin_with_period, primitive_float_asin_with_period_rational      
acos Acos, acos_prec_round   ✓  
acos acos_pi_prec_round   ✓  
acos acos_pi_rational_prec_round   ≈  
acos acos_rational_prec_round   ≈  
acos acos_with_period_prec_round   ✓  
acos acos_with_period_rational_prec_round   ≈  
acos primitive_float_acos, primitive_float_acos_pi, primitive_float_acos_pi_rational, primitive_float_acos_rational, primitive_float_acos_with_period, primitive_float_acos_with_period_rational      
atan Atan, atan_prec_round   ✓  
atan atan_pi_prec_round   ✓  
atan atan_pi_rational_prec_round   ≈  
atan atan_rational_prec_round   ≈  
atan atan_with_period_prec_round   ✓  
atan atan_with_period_rational_prec_round   ≈  
atan primitive_float_atan, primitive_float_atan_rational   ≈  
atan primitive_float_atan_pi, primitive_float_atan_pi_rational, primitive_float_atan_with_period, primitive_float_atan_with_period_rational      
atan2 Atan2, atan2_prec_round   ✓  
atan2 atan2_pi_prec_round   ✓  
atan2 atan2_pi_rational_prec_round      
atan2 atan2_rational_prec_round   ≈  
atan2 atan2_with_period_prec_round   ✓  
atan2 atan2_with_period_rational_prec_round      
atan2 primitive_float_atan2, primitive_float_atan2_pi, primitive_float_atan2_pi_rational, primitive_float_atan2_rational, primitive_float_atan2_with_period, primitive_float_atan2_with_period_rational      
asec Asec, asec_prec_round   ✓  
asec asec_pi_prec_round   ✓  
asec asec_pi_rational_prec_round   ≈  
asec asec_rational_prec_round   ≈  
asec asec_with_period_prec_round   ✓  
asec asec_with_period_rational_prec_round   ≈  
asec primitive_float_asec, primitive_float_asec_pi, primitive_float_asec_pi_rational, primitive_float_asec_rational, primitive_float_asec_with_period, primitive_float_asec_with_period_rational      
acsc Acsc, acsc_prec_round   ✓  
acsc acsc_pi_prec_round   ✓  
acsc acsc_pi_rational_prec_round   ≈  
acsc acsc_rational_prec_round   ≈  
acsc acsc_with_period_prec_round   ✓  
acsc acsc_with_period_rational_prec_round   ≈  
acsc primitive_float_acsc, primitive_float_acsc_pi, primitive_float_acsc_pi_rational, primitive_float_acsc_rational, primitive_float_acsc_with_period, primitive_float_acsc_with_period_rational      
acot Acot, acot_prec_round   ✓  
acot acot_pi_prec_round   ✓  
acot acot_pi_rational_prec_round   ≈  
acot acot_rational_prec_round   ≈  
acot acot_with_period_prec_round   ✓  
acot acot_with_period_rational_prec_round   ≈  
acot primitive_float_acot, primitive_float_acot_pi, primitive_float_acot_pi_rational, primitive_float_acot_rational, primitive_float_acot_with_period, primitive_float_acot_with_period_rational      

Each trigonometric function comes in several forms: of a Float in radians; of a Rational; of a multiple of \(\pi\) (sin_pi(x) is \(\sin \pi x\)); and with a period (sin_with_period(x, u) is \(\sin 2\pi x / u\) for an integer \(u\)), the last two each with a Float or a Rational argument. The Float forms are checked against MPFR directly, through mpfr_sin and its siblings, the mpfr_sinpi family, and the mpfr_sinu family, which takes the same integer period. The _pi and _with_period forms of sec, csc, and cot, which MPFR lacks, are checked against references that bracket the reciprocal of a wider-precision sine or cosine and round once both ends agree; on the rare inputs where the bracket does not settle the rounding, those references decline to answer and the input is passed over.

The Rational forms are ≈. MPFR takes only binary floating-point arguments, so the oracle first rounds the Rational to a Float with 128 more bits than the target precision, plus the bits of its denominator and exponent, and applies MPFR to that. The result agrees with the exact one except in the vanishingly rare case where the true value lies within those extra bits of a rounding boundary, and the tests require agreement on every input. The primitive_float_* versions of sin, cos, tan, sec, csc, cot, and atan are ≈ in a similar way: the oracle’s value is mapped into the primitive type, whose exponent range differs from MPFR’s, by rounding it once at the precision it has there (rounding first to more bits and then to the primitive type would round twice, which goes wrong for values just short of a midpoint of the primitive type). The other primitive forms are compared with the Float functions.

Hyperbolic functions

Operation Functions Azurite MPFR Reference
sinh Sinh, sinh_prec_round   ✓  
sinh sinh_rational_prec_round   ≈  
sinh primitive_float_sinh, primitive_float_sinh_rational   ≈  
cosh Cosh, cosh_prec_round   ✓  
cosh cosh_rational_prec_round   ≈  
cosh primitive_float_cosh, primitive_float_cosh_rational   ≈  
tanh Tanh, tanh_prec_round   ✓  
tanh tanh_rational_prec_round   ≈  
tanh primitive_float_tanh, primitive_float_tanh_rational   ≈  
sech Sech, sech_prec_round   ✓  
sech sech_rational_prec_round   ≈  
sech primitive_float_sech, primitive_float_sech_rational   ≈  
csch Csch, csch_prec_round   ✓  
csch csch_rational_prec_round   ≈  
csch primitive_float_csch, primitive_float_csch_rational   ≈  
coth Coth, coth_prec_round   ✓  
coth coth_rational_prec_round   ≈  
coth primitive_float_coth, primitive_float_coth_rational   ≈  
sinh_cosh SinhCosh, sinh_cosh_prec_round   ✓  
sinh_cosh sinh_cosh_rational_prec_round   ≈  
sinh_cosh primitive_float_sinh_cosh, primitive_float_sinh_cosh_rational      
asinh Asinh, asinh_prec_round   ✓  
asinh primitive_float_asinh   ≈  
asinh asinh_rational_prec_round   ≈  
asinh primitive_float_asinh_rational   ≈  
acosh Acosh, acosh_prec_round   ✓  
acosh primitive_float_acosh   ≈  
acosh acosh_rational_prec_round   ≈  
acosh primitive_float_acosh_rational   ≈  
atanh Atanh, atanh_prec_round   ✓  
atanh primitive_float_atanh   ≈  
atanh atanh_rational_prec_round   ≈  
atanh primitive_float_atanh_rational   ≈  
asech Asech, asech_prec_round   ≈  
asech primitive_float_asech   ≈  
asech asech_rational_prec_round   ≈  
asech primitive_float_asech_rational   ≈  
acsch Acsch, acsch_prec_round   ≈  
acsch primitive_float_acsch   ≈  
acsch acsch_rational_prec_round   ≈  
acsch primitive_float_acsch_rational   ≈  
acoth Acoth, acoth_prec_round   ≈  
acoth primitive_float_acoth   ≈  
acoth acoth_rational_prec_round   ≈  
acoth primitive_float_acoth_rational   ≈  

The hyperbolic functions, their reciprocals, sinh_cosh, and the inverse hyperbolic sine, cosine, and tangent of a Float are checked against MPFR directly. The Rational forms are ≈, for the reason given under Trigonometric functions. For the inverse hyperbolic cosine of a Rational near 1, the oracle adds as many bits as the magnitude of the exponent of \(x - 1\), since a relative error \(e\) in the input moves the result by about \(e/(2(x-1))\); for the inverse hyperbolic tangent of a Rational near \(\pm1\) it adds as many as the magnitude of the exponent of \(1 - |x|\), for the same reason.

The primitive_float_* versions are ≈: the oracle’s value is mapped into the primitive type, whose exponent range differs from MPFR’s. For sinh, cosh, tanh, asinh, and acosh, MPFR computes at the primitive type’s own precision and an overflow is mapped to infinity; for the others the value is rounded once at the precision it has in the primitive type, as under Trigonometric functions, which matters for values just short of a midpoint of the primitive type, such as \(\operatorname{acsch}(2^{150}/32767)\) in f32. primitive_float_sinh_cosh is compared with primitive_float_sinh and primitive_float_cosh.

MPFR has no inverse hyperbolic secant, cosecant, or cotangent, so every asech, acsch, and acoth row is ≈. For asech, the oracle evaluates \(\operatorname{acosh}(1/x)\) with MPFR for \(x \geq \frac{1}{2}\), the reciprocal being an exact Rational (with the extra input bits of the inverse hyperbolic cosine’s Rational oracle), and \(\ln(1+\sqrt{1-x^2}) - \ln x\) with 128 extra bits for smaller \(x\), where \(1/x\) could overflow. For acsch, it evaluates \(\operatorname{asinh}(1/x)\), the reciprocal again being exact, and for extreme exponents \(\ln(1+\sqrt{1+x^2}) - \ln|x|\) or the inverse hyperbolic sine of a reciprocal rounded with 128 extra bits. For acoth, it evaluates \(\operatorname{atanh}(1/x)\), whose Rational oracle’s extra input bits cover the ill-conditioning near \(|x| = 1\), or, for a huge \(x\), the inverse hyperbolic tangent of a reciprocal rounded with 128 extra bits. The property tests also compare each Float function with the Rational function of the exact reciprocal (acosh_rational_prec_round, asinh_rational_prec_round, or atanh_rational_prec_round), an independent Malachite computation, and each Rational function with the Float one.

Other functions

Operation Functions Azurite MPFR Reference
factorial factorial_prec_round   ✓  

The factorial of an integer, rounded to a precision, is checked against MPFR’s mpfr_fac_ui.

Conversion

From malachite_float::float::conversion.

Integers, naturals, and rationals

Operation Functions Azurite MPFR Reference
from_natural TryFrom<Natural> ✓    
from_natural ConvertibleFrom<Natural>      
from_natural from_natural_prec, from_natural_prec_round ✓ ✓  
from_integer TryFrom<Integer> ✓    
from_integer ConvertibleFrom<Integer>      
from_integer from_integer_prec, from_integer_prec_round ✓ ✓  
from_rational TryFrom<Rational>, ConvertibleFrom<Rational>      
from_rational from_rational_prec, from_rational_prec_round ✓ ✓  
natural_from_float RoundingFrom<Float>, TryFrom<Float>, ConvertibleFrom<Float> for Natural      
integer_from_float RoundingFrom<Float> for Integer   ✓  
integer_from_float TryFrom<Float>, ConvertibleFrom<Float> for Integer      
rational_from_float TryFrom<Float> for Rational   ✓  
rational_from_float ConvertibleFrom<Float> for Rational      
from_bits non_dyadic_from_bits_prec, non_dyadic_from_bits_prec_round     ✓
from_digits non_dyadic_from_digits_prec, non_dyadic_from_digits_prec_round, non_dyadic_from_power_of_2_digits_prec, non_dyadic_from_power_of_2_digits_prec_round     ✓
is_integer IsInteger      
is_real IsReal      

Conversion from a Natural, an Integer, or a Rational to a given precision and rounding mode is checked by Azurite (setPrecRound of the exact ofAzNat or ofAzInt value, and ofAzRatRound) and MPFR; the exact conversions from a Natural or Integer (TryFrom, which uses the least precision that holds the value and fails only when the value is too large for the exponent range) by Azurite. Rounding a Float to an Integer is checked against MPFR’s conversion in each rounding mode, and the exact conversion to a Rational against MPFR’s. The conversions to Natural, the fallible conversions to Integer, and the ConvertibleFrom predicates are covered by property tests. The non_dyadic_from_* constructors build a Float from an infinite stream of bits or digits whose value is known not to be dyadic. They are checked against a reference that brackets the value between exact Rationals, on irrational digit streams and on the expansions of non-dyadic Rationals in many bases; on the latter they must also agree with from_rational_prec_round, which Azurite and MPFR check.

Primitive types

Operation Functions Azurite MPFR Reference
from_primitive_int From<u8>, …, From<usize> ✓ ✓  
from_primitive_int From<i8>, …, From<isize>   ✓  
from_primitive_int from_unsigned_prec, from_unsigned_prec_round, from_signed_prec, from_signed_prec_round   ✓  
from_primitive_int const_from_unsigned, const_from_signed, const_from_unsigned_times_power_of_2, const_from_signed_times_power_of_2      
primitive_int_from_float RoundingFrom<Float>, TryFrom<Float>, ConvertibleFrom<Float> for every primitive integer      
from_primitive_float From<f32>, From<f64>   ✓  
from_primitive_float from_primitive_float_prec, from_primitive_float_prec_round   ✓  
primitive_float_from_float RoundingFrom<Float> for f32, f64   ✓  
primitive_float_from_float TryFrom<Float>, ConvertibleFrom<Float> for f32, f64      

Conversion from every primitive integer and float type, exactly or to a given precision, is checked against MPFR, and from the unsigned types also by Azurite. Rounding a Float to an f32 or f64 is compared with MPFR’s own conversion in every rounding mode, subnormal results included. The conversions to the primitive integers, the exact float conversions, and the const constructors are covered by property tests.

Mantissa and exponent

Operation Functions Azurite MPFR Reference
mantissa_and_exponent RawMantissaAndExponent      
mantissa_and_exponent IntegerMantissaAndExponent      
mantissa_and_exponent SciMantissaAndExponent with a Float mantissa      
mantissa_and_exponent SciMantissaAndExponent with an f32 or f64 mantissa, sci_mantissa_and_exponent_round      

The decompositions of a Float into a mantissa and an exponent (the raw significand and exponent, an odd integer mantissa, and a mantissa in \([1, 2)\) as a Float or a primitive float) are covered by unit and property tests, including round trips through their from_* inverses.

Gaussian integers and rationals

Operation Functions Azurite MPFR Reference
from_gaussian_integer TryFrom<GaussianInteger>, ConvertibleFrom<GaussianInteger>      
from_gaussian_rational TryFrom<GaussianRational>, ConvertibleFrom<GaussianRational>      
gaussian_integer_from_float TryFrom<Float>, ConvertibleFrom<Float> for GaussianInteger      
gaussian_rational_from_float TryFrom<Float>, ConvertibleFrom<Float> for GaussianRational      
is_gaussian_integer IsGaussianInteger      

The conversions between a Float and the Gaussian types succeed exactly when the imaginary part is zero and the real part converts, and they are covered by property tests.

Strings

Operation Functions Azurite MPFR Reference
to_string Display, Debug for Float and ComparableFloat      
to_string Binary, Octal, LowerHex, UpperHex, ToStringBase      
from_string FromStr, FromStringBase for Float and ComparableFloat      
from_sci_string FromSciString, from_sci_string_prec, from_sci_string_prec_round, from_sci_string_with_options_prec     ✓
to_sci ToSci      
get_str get_str   ✓  
get_str get_str_digit_count      
strtofr strtofr, set_str   ✓  
format_float format_float_str, GmpFormatArg   ✓  
latex ToLatex      
typst ToTypst      
serde Serialize, Deserialize      

The MPFR-style string functions are checked against MPFR itself: get_str against mpfr_get_str, strtofr and set_str against mpfr_strtofr and mpfr_set_str, and the printf-style format_float_str against mpfr_snprintf. Parsing scientific notation to a precision is checked against a reference that parses the string exactly as a Rational and rounds it once. Malachite’s own Display (enough correctly rounded digits, a number fixed by the precision, to read back to the same Float), Debug, the base and hexadecimal formatting, FromStr, ToSci, and LaTeX, Typst, and serde output are covered by property tests, chiefly round trips: a printed value, with its precision, must parse back to the same Float.

Exhaustive generation

This section is not yet written.

Random generation

This section is not yet written.

What is not yet cross-checked

This section is not yet written.