floating

This manual documents the main branch of Luna-Flow/floating, which builds on the latest published stable release, 0.11.0; the changes since that release are listed in the changelog.

Overview

floating is arbitrary-precision floating-point arithmetic for MoonBit: binary values with IEEE 754 semantics at any precision, IEEE 754 and General Decimal Arithmetic decimals, and certified interval arithmetic following IEEE 1788. Precision, rounding, exponent range, special values, status flags, traps and enclosures are explicit values in every API rather than hidden global state.

The library is built around three contracts:

  • A rounded operation computes the exact real result and rounds it once, so the error of one step is at most one unit in the last place, and at most half of one under round-to-nearest.
  • A decimal keeps its quantum: 1.20 and 1.2 are equal numbers with different exponents, and every operation states which exponent it prefers.
  • An interval operation returns a set that contains every exact result of its operands, so a chain of interval operations encloses the exact value of the whole expression.

Install

moon add Luna-Flow/floating@0.11.0

Then import the packages you need in your moon.pkg:

import {
  "Luna-Flow/floating/binary",
}

The module needs the MoonBit toolchain 0.10.20 or later (moonc ≥ 0.10.20). It depends on Luna-Flow/arithmetic (rounding modes, contexts, checked and contextual traits) and Luna-Flow/luna-generic (algebraic traits); add Luna-Flow/arithmetic yourself when you name its types. Getting started walks through the first program.

Modules

The repository is a workspace of two modules. Luna-Flow/floating (directory library/) is the library: the numerical cores, the checked wrappers, def, and the internal helpers. Luna-Flow/floating-tools (directory tooling/, versioned with the library) holds the developer tools: expressions and corpus frontends, the conformance command line, the differential harness, the benchmarks and the documentation examples. The sections below say which module a package belongs to; their package names are import paths below the module name, so binary is Luna-Flow/floating/binary and frontend/gda_expr is Luna-Flow/floating-tools/frontend/gda_expr.

Pages

Each documented package has a tutorial (how to use it), an API reference (what you can call) and a design page (why it works this way). The four numerical cores also have a conformance page (which standard behaviour is verified, and how) and a performance page (measurements and their method).

Numerical cores

PartTutorialAPIDesignEvidence
binary: binary floating point, IEEE 754 binary operations, binary16/32/64/128 interchangetutorialAPIdesignconformance, performance
decimal: IEEE 754 decimal with per-operation flags and DPD/BID interchangetutorialAPIdesignconformance, performance
decimal_gda: General Decimal Arithmetic with sticky status and trapstutorialAPIdesignconformance, performance
interval: outward-rounded bare and decorated intervals (IEEE 1788)tutorialAPIdesignconformance, performance

Composition and shared vocabulary

PartTutorialAPIDesign
def: Sign, PartialOrder, the Floating trait, re-exported arithmetic typestutorialAPIdesign
binary_checked: binary pipelines that stop at the first errortutorialAPIdesign
decimal_checked: IEEE decimal pipelines that accumulate flagstutorialAPIdesign
decimal_gda_checked: GDA pipelines that thread status and stop at trapstutorialAPIdesign
interval_checked: interval pipelines that stop at the first errortutorialAPIdesign

Tools module: expressions and corpus frontends

PartTutorialAPIDesign
numeric_expr: host-independent numeric expression syntax and evaluationtutorialAPIdesign
frontend/gda_expr: parse and execute GDA .decTest filestutorialAPIdesign
frontend/itl_expr: parse and execute ITF1788 interval test rowstutorialAPIdesign
frontend/mpfr_expr: parse and execute pinned MPFR witnessestutorialAPIdesign
frontend/testfloat_expr: parse and execute Berkeley TestFloat vectorstutorialAPIdesign

Tools module: conformance command line

PartTutorialAPIDesign
cli: native dispatcher for the four conformance backendstutorialAPIdesign
cli/dispatch: the argument scanning and exit code of cli, as a librarytutorialAPIdesign
cli/gda_expr_cli: file and output adapter for .decTest runstutorialAPIdesign
cli/itl_expr_cli: file and JSON adapter for ITF1788 runstutorialAPIdesign
cli/mpfr_expr_cli: command adapter for MPFR witness runstutorialAPIdesign
differential: seeded random differential harness against MPFR and libmpdectutorialAPIdesign
differential/harness: the batches, specification and run of differential, as a librarytutorialAPIdesign
differential/interval_mpfr: the untimed differential stage of Interval against MPFRtutorialAPIdesign
cli/testfloat_expr_cli: command adapter for TestFloat runstutorialAPIdesign

Library infrastructure

PartTutorialAPIDesign
internal: exact rationals, big-integer, parsing, normalization and rounding helperstutorialAPIdesign
internal/decimal_kernel: exact integer arithmetic on decimal coefficients, shared by decimal and decimal_gdatutorialAPIdesign
internal/binary_kernel: exact integer arithmetic on the coefficients of binarytutorialAPIdesign

Tools module: infrastructure and evidence

PartTutorialAPIDesign
internal/conformance: source locations, deterministic shards, case dispositions and summariestutorialAPIdesign
internal/runner_cli: shared command-line options, files, diagnostics and JSONtutorialAPIdesign
semantic: exact, representation-independent projection for comparisons across packagestutorialAPIdesign
consistency: white-box cross-package laws and API auditstutorialAPIdesign
doc_examples: executable documentation examples run by just docstutorialAPIdesign
bench: shared Maremark benchmark infrastructuretutorialAPIdesign
bench/binary: binary arithmetic and elementary-function benchmarkstutorialAPIdesign
bench/decimal: IEEE decimal benchmarkstutorialAPIdesign
bench/decimal_gda: GDA decimal benchmarkstutorialAPIdesign
bench/interval: interval arithmetic benchmarkstutorialAPIdesign
bench/external: timing against MPFR and libmpdec on shared operandstutorialAPIdesign, performance

Guides

GuideRead it for
Getting startedchoosing a package, installing, first values, contexts and failure models
Numeric semanticsthe shared vocabulary: exact value and rounded result, rounding functions, ulp and unit roundoff, flags, quantum, signed zero, NaN, enclosures
Architecturepackage layers, the numeric core pipeline, certified elementary functions, invariants
Verificationthe gates, the published conformance claims and how to reproduce them
Performance auditproofs and evidence for the optimized arithmetic paths
External baselinefloating timed against MPFR and libmpdec: method, machine, ratios
Repository conventionsdocumentation rules and the review checklist

The application surface is the numerical cores, def and the checked wrappers; semantic and numeric_expr are provisional integration surfaces. The other packages publish interfaces because repository tools compose them, and their design pages state narrower stability promises.

Exported types

Binary floating point (binary)

  • Values: Binary (signed dyadic number with a precision, signed zeros, infinities and NaNs with payloads) and its exact coefficient BinCoeff
  • Contexts and status: BinaryContext, BinaryRoundingMode, TininessDetection, BinaryFlags
  • Interchange: BinaryInterchange, BinaryInterchangeFormat (binary16, 32, 64, 128 and wider)
  • Limits: binary_value_e_min, binary_value_e_max, binary_precision_max

Decimal floating point (decimal, decimal_gda)

  • IEEE 754 decimal: Decimal, DecimalContext, DecimalRoundingMode, DecimalFlags, and the DPD/BID interchange types DecimalInterchange, DecimalInterchangeFormat, DecimalInterchangeEncoding
  • General Decimal Arithmetic: Decimal, GdaContext, GdaRoundingMode, GdaFlags, GdaSignal, GdaTrapSet, GdaOutcome, GdaInterchange, GdaInterchangeFormat, and one free function per GDA operation (add, divide, quantize, power, …)

Intervals (interval)

  • Interval (bare interval), DecoratedInterval with its Decoration, OverlapState
  • IntervalContext and IntervalFlags for intervals in a target format

Pipelines and shared vocabulary

  • Checked wrappers: BinaryChecked, DecimalChecked, GdaDecimalChecked, IntervalChecked
  • def: Sign, PartialOrder, the Floating trait, is_finite, is_infinite, is_nan, is_zero, and the re-exported RoundingMode, ArithmeticContext and ArithmeticError of Luna-Flow/arithmetic
  • semantic: ExactRational, SemanticScalar, SemanticInterval, SemanticResult, SemanticError
  • numeric_expr: Expr, Literal, Operation, SourceSpan, EvalError and evaluate

Evidence snapshot

  • The pinned GDA official corpus passes 64,986/64,986 legal executable scalar rows, and official0 passes 16,124/16,124. The 141 # placeholder or non-scalar rows are diagnostic exclusions.
  • The binary TestFloat level-1 matrix passes 254,227,872 vectors across binary16/32/64/128, including fused multiply-add, remainder, round to integral, integer conversions and the comparison predicates, plus pinned MPFR square-root and elementary-function witnesses.
  • The strict ITF1788 aggregate passes 6,632/6,632 selected interval cases.
  • The IEEE decimal gate covers decimal32/64/128 DPD and BID encodings, flags and arithmetic on four targets.

These finite results do not imply support for every operation, every future corpus revision or every real input. Read the conformance page of a package before turning a result into a compatibility claim.

Validation

Recommended checks before a release, from the repository root:

moon check
moon test
just docs      # manual structure, links, API snapshots and examples
just pr 8      # the fast pull-request gate
just ci 8      # every gate, including the pinned conformance corpora

Verification explains each gate and how to reproduce a published result.

pkg.generated.mbti defines what is public, and source and tests define behaviour; if a page and the generated interface disagree, the interface wins.