Output Format

Precision

This module uses native hardware precision. A double provides approximately 15–17 significant decimal digits — the same precision as any standard calculator or spreadsheet. There are no precision tiers to choose from; what you see is what the CPU computes.

Exact vs. Approximate Results

  • = green — The displayed result is the exact internal value. This applies to all integer arithmetic (1+2 = 3), and to floating-point values that happen to be exactly representable in binary, such as 0.75, 0.5, 0.125, or 100000.
  • orange — The displayed result is a clean rounded view. Click to expand and see the full internal value. This happens whenever a decimal number cannot be represented exactly in binary. For example, 0.1 is stored internally as 0.100000000000000005551115123... and 0.1+0.2 evaluates to 0.300000000000000044408920985..., not 0.3.

This is not a bug — it is how IEEE 754 binary floating-point works in every programming language and processor. The signal makes this visible rather than hiding it.

When to Use

Choose the c++ module when you want standard calculator behavior, fast execution, and compatibility with how numbers work in C, C++, Java, Python, JavaScript, and most other languages. It is the best module for understanding how your code actually computes.

Reference

  • Standard: ISO/IEC 14882:2023 (C++23)
  • Author: Bjarne Stroustrup
  • Documentation: cppreference.com

Unlike binary floating-point, numbers are stored in base 10 — meaning 0.1+0.2=0.3 exactly, with no rounding error.

Precision Tiers

TierGuaranteed DigitsBest For
5050 decimal digitsGeneral-purpose high precision
100100 decimal digitsFinancial modeling, scientific constants
500500 decimal digitsExtreme precision requirements

All tiers are available for both real and complex types.

Exact vs. Approximate Results

  • = green — The displayed result is exact. Because this module stores values in base 10, common decimal fractions are represented without error. Most results you will see with this module are green.
  • orange — The displayed result has been rounded because it exceeds the display width. Click to expand and see more digits. This typically happens with expressions like 1/3 at high precision.

Note: in this module does not indicate a binary rounding error (there are none). It simply means more digits are available than what is displayed.

When to Use

Choose the dec module for financial calculations, currency conversions, or any domain where decimal exactness matters. It eliminates the class of bugs caused by binary floating-point representation.

Reference

  • Library: Boost.Multiprecision (cpp_dec_float)
  • Version: 1.87.0
  • License: BSL-1.0 (Boost Software License)
  • Author: John Maddock
  • Documentation: boost.org/multiprecision

Its distinguishing feature is exact rational arithmetic: 1/3 stays as the fraction 1/3, and 1/3*3=1 exactly — no rounding, no truncation.

Type System

  • mpz — Arbitrary-precision integers. No overflow, no limit.
  • mpq — Exact rationals (fractions). 1/3+1/6=1/2 with zero error. This is the default integer type, so 1/2 evaluates to the fraction 1/2 rather than 0.
  • mpf50 / mpf100 / mpf500 — Binary floating-point at 50, 100, or 500 digit precision. Used when operations leave the rational domain (e.g., sqrt(2)).
  • rqc — Rational complex. Exact complex arithmetic with two mpq components: (1+i)/(1-i) = i exactly. When irrational operations are needed, values promote to float-backed complex (gmpc50/100/500).

Precision Tiers

TierInteger / RationalFloatComplex
50Exact (unlimited)50 decimal digitsExact rational or 50-digit float
100Exact (unlimited)100 decimal digitsExact rational or 100-digit float
500Exact (unlimited)500 decimal digitsExact rational or 500-digit float

The precision tier only affects floating-point operations. Integers and rationals are always exact regardless of the selected tier.

Exact vs. Approximate Results

  • = green — The displayed result is exact.
  • orange — The displayed result is a clean rounded view of a binary float. Click to expand. This happens when the result is a mpf float — for example, 0.1 stored in binary is 0.0999...999 at 50-digit precision.

The key advantage: if you stay within integer and rational operations, everything is green. Binary approximation only appears when you explicitly use decimal literals (0.1) or transcendental functions (sin, sqrt).

When to Use

Choose the gmp module for number theory, exact arithmetic, symbolic-style computation, or any domain where fractions must remain exact. It is the best module for educational contexts where 1/3*3 should equal 1, and for cryptographic applications requiring arbitrary-precision integers.

Reference

  • Library: GMP (GNU Multiple Precision Arithmetic Library)
  • Version: 6.3.0
  • License: LGPL-3.0
  • Author: GNU Project
  • Documentation: gmplib.org

The interval module wraps every number in a guaranteed enclosure [lower, upper]. The true mathematical result is always contained within the interval bounds. This makes rounding errors visible and quantifiable instead of hidden.

How It Works

Every floating-point operation is computed twice: once rounding down (for the lower bound) and once rounding up (for the upper bound). The resulting interval is guaranteed to contain the exact mathematical result. When both bounds are equal, the result is exact. When they differ, the gap reveals the accumulated rounding error.

Types

TypeWrapsPrecision
ifloatinterval<float>~7 decimal digits
idouble (default)interval<double>~15 decimal digits
ildoubleinterval<long double>~18 decimal digits

Unsuffixed literals (0.1, 1.0) default to ildouble. Use explicit constructors for other types: ifloat(0.1), ildouble(0.1).

The Classic Example

Try 0.1+0.2. In every other module, you get a single number. Here you get an interval:

  • Display: ≈ [0.3, 0.3] — the smart-rounded view looks clean
  • Expand: [0.29999999999999999, 0.30000000000000004] — the true bounds reveal that 0.3 is enclosed but not exact

Compare with 0.5+0.5 which gives = [1, 1] — a point interval, because 0.5 and 1.0 are exactly representable in binary.

Exact vs. Approximate Results

  • = green — Both bounds are identical: the result is a point interval with no rounding error. Examples: 0.5+0.5, 2.0*3.0, 0.5+0.25.
  • orange — The bounds differ: rounding error is present. Click to expand and see the exact bounds. The gap between bounds quantifies the accumulated error.

Comparisons and Indeterminacy

Comparing intervals is fundamentally different from comparing numbers. When two intervals overlap, the comparison is indeterminate: neither true nor false can be guaranteed. In that case, the module throws a comparison_error.

ExpressionResultWhy
1.0+1.0==2.0trueBoth sides are point intervals, identical
0.1+0.2==0.3uncertain comparisonIntervals overlap — cannot determine equality

This is not a limitation — it is the mathematically correct answer. If two intervals overlap, claiming they are equal or unequal would be a lie. The module refuses to guess.

When to Use

Choose the ival module to understand and visualize rounding error propagation. It is ideal for numerical analysis education, validating the stability of algorithms, and any context where you need a guaranteed enclosure of the true result rather than a best-effort approximation.

Reference

  • Library: Boost.Numeric.Interval
  • Version: 1.87.0
  • License: BSL-1.0 (Boost Software License)
  • Author: Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
  • Documentation: boost.org/numeric/interval

The mpfr module provides high-precision binary floating-point and complex arithmetic using the MPFR and MPC libraries. It is the go-to module for scientific computing where you need many digits of precision with correctly-rounded results.

Precision Tiers

TierReal TypeComplex TypeGuaranteed Digits
50mpfr50mpc5050 decimal digits
100mpfr100mpc100100 decimal digits
500mpfr500mpc500500 decimal digits

MPFR guarantees correct rounding for every basic operation: the result is the closest representable value to the exact mathematical result.

Exact vs. Approximate Results

  • = green — The displayed result is the exact internal value. This applies to values that happen to be exactly representable in binary: 0.75, 0.5+0.25, 0, and integer-valued floats like 100000.
  • orange — The displayed result is a clean rounded view. Click to expand and see the full-precision value. Like all binary floating-point, decimal fractions such as 0.1 and 0.1+0.2 are not exact.

The key difference from c++: with 50–500 digits of precision, the binary error is pushed far to the right. The result is still approximate, but the approximation is vastly more precise than a double.

Comparison with Other Modules

Expressionc++ (double)mpfr50dec50gmp (mpq)
0.1+0.2≈ 0.3 (16 digits)≈ 0.3 (50 digits)= 0.3 (exact)≈ 0.3 (50 digits)
0.75= 0.75= 0.75= 0.75= 0.75
1/3N/A≈ 0.333…≈ 0.333…= 1/3
sqrt(2)≈ 1.414… (16 digits)≈ 1.414… (50 digits)≈ 1.414… (50 digits)≈ 1.414… (50 digits)

MPFR excels at transcendental functions (sin, cos, exp, log, sqrt) where every digit is correctly rounded. For pure rational arithmetic, consider the gmp module instead.

When to Use

Choose the mpfr module for scientific calculations requiring many digits of verified precision: computing mathematical constants, evaluating convergence of series, numerical analysis, or any domain where you need to distinguish between true results and floating-point artifacts.

Reference

  • Library: MPFR (floats) + MPC (complex)
  • Version: MPFR 4.2.1 / MPC 1.3.1
  • License: LGPL-3.0
  • Author: GNU Project
  • Documentation: mpfr.org

The bin module provides high-precision binary floating-point and complex arithmetic using Boost.Multiprecision cpp_bin_float. It is a pure C++ alternative to mpfr — no external library required — with configurable decimal digit precision.

Precision Tiers

TierReal TypeComplex TypePrecision
50bin50binc5050 decimal digits
100bin100binc100100 decimal digits
500bin500binc500500 decimal digits

Exact vs. Approximate Results

  • = green — The displayed result is the exact internal value. Values exactly representable in binary — 0.75, 0.5, 0.125 — are always green.
  • orange — The displayed result is a clean rounded view. Click to expand and see the full-precision value. Like all binary floating-point, decimal fractions such as 0.1 and 0.1+0.2 are not exactly representable in binary.

The behavior is identical to mpfr: binary representation errors exist, but are pushed much further right with each precision tier.

Comparison with mpfr

binmpfr
BackendPure C++ (Boost, header-only)MPFR + MPC (C library)
DependencyNone beyond Boostlibmpfr, libmpc, libgmp
Correct roundingBasic operations (+−×÷, sqrt)All operations including transcendentals
TranscendentalsVia Boost.Math (not all guaranteed)Full support (sin, cos, exp, log…)

When to Use

Choose the bin module when you want high-precision binary floating-point without any external library dependency. It is a good drop-in replacement for mpfr in environments where the MPFR library is unavailable. For certified scientific results requiring correctly-rounded transcendentals, prefer mpfr.

Reference

  • Library: Boost.Multiprecision (cpp_bin_float)
  • Version: 1.87.0
  • License: BSL-1.0 (Boost Software License)
  • Author: John Maddock
  • Documentation: boost.org — cpp_bin_float

The int module provides exact integer arithmetic at arbitrary or fixed precision using Boost.Multiprecision cpp_int. Every result is exact — no floating-point, no rounding, and no overflow for the arbitrary-precision type.

Type System

TypeWidthSignRange
cpp_intArbitrary (grows as needed)SignedUnlimited — never overflows
int128 / int256 / int512 / int1024FixedSigned±2N−1
uint128 / uint256 / uint512 / uint1024FixedUnsigned0 to 2N−1

Unsuffixed integer literals default to cpp_int. Use explicit type names for fixed-width: int512(x), uint256(x).

Exact vs. Approximate Results

  • = green — Always. Integer arithmetic is exact by definition. There is no in this module.

Overflow Behavior

  • cpp_int — Never overflows. The value grows dynamically to accommodate any result. 2^1000 is computed exactly.
  • intN / uintN — Overflow wraps silently (unchecked mode). Use cpp_int if overflow safety matters.

Note: unary minus is not defined for unsigned types (uint128, etc.) — negating an unsigned value is mathematically undefined.

Division

Division between integers performs integer division truncated toward zero: 7/2 = 3, -7/2 = -3. For exact rational results, use the gmp module (mpq).

When to Use

Choose the int module for combinatorics, cryptography, number theory, or any computation requiring exact integer results beyond the 64-bit limit. cpp_int is ideal for factorials, large powers, and primality testing. Fixed-width types are useful when a specific bit width is required, for example to match a hardware or protocol specification.

Reference

  • Library: Boost.Multiprecision (cpp_int)
  • Version: 1.87.0
  • License: BSL-1.0 (Boost Software License)
  • Author: John Maddock
  • Documentation: boost.org — cpp_int