Skip to main content

Module native

Module native 

Source
Expand description

Native binary-base arbitrary-precision floating-point implementation.

This module is additive: the crate-root BigFloat alias remains dashu_float::DBig (decimal). Reach for native::BigFloat when you want ground-up Pure Rust binary float arithmetic with explicit rounding-mode control. The native type is intentionally not re-exported at the crate root to avoid clashing with the DBig alias. Native arbitrary-precision floating-point implementation.

This module provides BigFloat, a binary-base (b = 2) arbitrary precision floating-point number with explicit precision tracking and post-operation rounding. It is implemented in pure safe Rust on top of the native oxinum_int::native::BigUint limb-vector integer.

The wrapper-level crate::BigFloat alias (decimal-base DBig via dashu-float) is a separate type — they coexist intentionally. Reach for the native BigFloat when you need ground-up Pure Rust binary arithmetic with explicit rounding-mode control.

§Phase 2 scope (this module)

  • Construction / decomposition: zero, nan, infinity, neg_infinity, from_i64, from_f64, to_f64, from_parts, with_precision, round_to_precision.
  • Accessors: precision, sign, mantissa, exponent, is_zero, is_finite, is_infinite, is_nan, is_normal, classify, is_sign_positive, is_sign_negative, signum, abs, neg.
  • Classification: FloatClass enum (Finite, Infinite, Nan).
  • Arithmetic: Add, Sub, Neg, plus the *Assign variants.
  • Comparison: PartialOrd, PartialEq (precision-independent, NaN-aware). Note: Ord and Eq are not implemented — NaN breaks reflexivity and totality. Use BigFloat::total_cmp for a sort-stable total order.
  • Display: hex-float-like 0xb<binary>p<exponent>, NaN, inf, -inf.

Multiplication, division, and square root land in float_mul, float_div, and float_sqrt. They feed back through BigFloat::from_parts so the canonical-form invariants are uniformly enforced.

§Examples

use oxinum_float::native::{BigFloat, RoundingMode};

let one = BigFloat::from_i64(1, 32, RoundingMode::HalfEven);
let two = BigFloat::from_i64(2, 32, RoundingMode::HalfEven);
let sum = &one + &two;
assert_eq!(sum.to_f64(), 3.0);

let three = BigFloat::from_i64(3, 32, RoundingMode::HalfEven);
let six = &two * &three;
assert_eq!(six.to_f64(), 6.0);

Modules§

binary_splitting
Binary-splitting engine for hypergeometric-like series.
nonfinite
IEEE-754 non-finite propagation helpers for native BigFloat arithmetic.

Structs§

BigFloat
Native arbitrary-precision binary float.
FloatContext
Precision context for native BigFloat computations.

Enums§

FloatClass
Classification of a BigFloat value: finite, infinite, or NaN.
RoundingMode
Rounding modes for native BigFloat arithmetic.

Functions§

e_const
Return e (Euler’s number) at prec bits of precision.
ln2
Return ln 2 at prec bits of precision.
pi
Return π at prec bits of precision.