Crate mpmfnum

source ·
Expand description

Number formats, precisions, and rounding modes.

mpmfnum is a numbers library for emulation various number formats, at multiple precisions with many rounding modes. Hence its name “Multi-Precision, Multi-Format” (MPMF). Unlike other number libraries like BigInt or Rug (MPFR), this library emphasizes a clean abstraction of various computer number systems rather than high-performance computation.

This library embraces design principles found in the FPCore standard. Most importantly, numerical programs need only be specified by (i) real-number mathematical operations and (ii) rounding. Number formats, e.g., double or float, are not first-class, as in most programming languages. Rather, formats are side effects of rounding and should be de-emphasized or eliminated entirely. Furthermore, all values within a numerical program should be viewed as (extended) real numbers.

These design principles are reflected in the two primary traits of this library:

For implementation purposes, we restrict any Real value to be of the form (-1)^s * c * 2^exp where s is 0 or 1, c is a non-negative integer, and exp is an integer. Implementations of RoundingContext may support any of the numerous operations (as traits) found under crate::ops. Operations provided by this library are correctly rounded.

mpmfnum supports various number systems through implementations of RoundingContext:

  • RealContext performs no rounding, that is, the operation is exact,
  • RFloatContext rounds a Real value to an arbitrary-precision, floating-point numbers with unbounded exponent,
  • FloatContext rounds a Real value to a fixed-precision, floating-point numbers with unbounded exponent,
  • IEEE754Context rounds a Real value to a floating-point number as described by the IEEE 754 standard,
  • FixedContext rounds a Real value to a fixed-point,

Planned support for posits and more!


  • Multiple flavors of fixed-point numbers.
  • Fixed-precision, floating-pont numbers with unbounded exponent.
  • Floating-point numbers as described in the IEEE 754-2019 standard.
  • Round-to-odd arithmetic.
  • Rounded mathematical operations.
  • Exact arithmetic.
  • Floating-point numbers with unbounded significand and exponent.



  • Universal trait for extended real numbers.
  • Universal trait for rounding contexts.