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.20and1.2are 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
| Part | Tutorial | API | Design | Evidence |
|---|---|---|---|---|
binary: binary floating point, IEEE 754 binary operations, binary16/32/64/128 interchange | tutorial | API | design | conformance, performance |
decimal: IEEE 754 decimal with per-operation flags and DPD/BID interchange | tutorial | API | design | conformance, performance |
decimal_gda: General Decimal Arithmetic with sticky status and traps | tutorial | API | design | conformance, performance |
interval: outward-rounded bare and decorated intervals (IEEE 1788) | tutorial | API | design | conformance, performance |
Composition and shared vocabulary
| Part | Tutorial | API | Design |
|---|---|---|---|
def: Sign, PartialOrder, the Floating trait, re-exported arithmetic types | tutorial | API | design |
binary_checked: binary pipelines that stop at the first error | tutorial | API | design |
decimal_checked: IEEE decimal pipelines that accumulate flags | tutorial | API | design |
decimal_gda_checked: GDA pipelines that thread status and stop at traps | tutorial | API | design |
interval_checked: interval pipelines that stop at the first error | tutorial | API | design |
Tools module: expressions and corpus frontends
| Part | Tutorial | API | Design |
|---|---|---|---|
numeric_expr: host-independent numeric expression syntax and evaluation | tutorial | API | design |
frontend/gda_expr: parse and execute GDA .decTest files | tutorial | API | design |
frontend/itl_expr: parse and execute ITF1788 interval test rows | tutorial | API | design |
frontend/mpfr_expr: parse and execute pinned MPFR witnesses | tutorial | API | design |
frontend/testfloat_expr: parse and execute Berkeley TestFloat vectors | tutorial | API | design |
Tools module: conformance command line
| Part | Tutorial | API | Design |
|---|---|---|---|
cli: native dispatcher for the four conformance backends | tutorial | API | design |
cli/dispatch: the argument scanning and exit code of cli, as a library | tutorial | API | design |
cli/gda_expr_cli: file and output adapter for .decTest runs | tutorial | API | design |
cli/itl_expr_cli: file and JSON adapter for ITF1788 runs | tutorial | API | design |
cli/mpfr_expr_cli: command adapter for MPFR witness runs | tutorial | API | design |
differential: seeded random differential harness against MPFR and libmpdec | tutorial | API | design |
differential/harness: the batches, specification and run of differential, as a library | tutorial | API | design |
differential/interval_mpfr: the untimed differential stage of Interval against MPFR | tutorial | API | design |
cli/testfloat_expr_cli: command adapter for TestFloat runs | tutorial | API | design |
Library infrastructure
| Part | Tutorial | API | Design |
|---|---|---|---|
internal: exact rationals, big-integer, parsing, normalization and rounding helpers | tutorial | API | design |
internal/decimal_kernel: exact integer arithmetic on decimal coefficients, shared by decimal and decimal_gda | tutorial | API | design |
internal/binary_kernel: exact integer arithmetic on the coefficients of binary | tutorial | API | design |
Tools module: infrastructure and evidence
| Part | Tutorial | API | Design |
|---|---|---|---|
internal/conformance: source locations, deterministic shards, case dispositions and summaries | tutorial | API | design |
internal/runner_cli: shared command-line options, files, diagnostics and JSON | tutorial | API | design |
semantic: exact, representation-independent projection for comparisons across packages | tutorial | API | design |
consistency: white-box cross-package laws and API audits | tutorial | API | design |
doc_examples: executable documentation examples run by just docs | tutorial | API | design |
bench: shared Maremark benchmark infrastructure | tutorial | API | design |
bench/binary: binary arithmetic and elementary-function benchmarks | tutorial | API | design |
bench/decimal: IEEE decimal benchmarks | tutorial | API | design |
bench/decimal_gda: GDA decimal benchmarks | tutorial | API | design |
bench/interval: interval arithmetic benchmarks | tutorial | API | design |
bench/external: timing against MPFR and libmpdec on shared operands | tutorial | API | design, performance |
Guides
| Guide | Read it for |
|---|---|
| Getting started | choosing a package, installing, first values, contexts and failure models |
| Numeric semantics | the shared vocabulary: exact value and rounded result, rounding functions, ulp and unit roundoff, flags, quantum, signed zero, NaN, enclosures |
| Architecture | package layers, the numeric core pipeline, certified elementary functions, invariants |
| Verification | the gates, the published conformance claims and how to reproduce them |
| Performance audit | proofs and evidence for the optimized arithmetic paths |
| External baseline | floating timed against MPFR and libmpdec: method, machine, ratios |
| Repository conventions | documentation 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 coefficientBinCoeff - 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 typesDecimalInterchange,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),DecoratedIntervalwith itsDecoration,OverlapStateIntervalContextandIntervalFlagsfor intervals in a target format
Pipelines and shared vocabulary
- Checked wrappers:
BinaryChecked,DecimalChecked,GdaDecimalChecked,IntervalChecked def:Sign,PartialOrder, theFloatingtrait,is_finite,is_infinite,is_nan,is_zero, and the re-exportedRoundingMode,ArithmeticContextandArithmeticErrorofLuna-Flow/arithmeticsemantic:ExactRational,SemanticScalar,SemanticInterval,SemanticResult,SemanticErrornumeric_expr:Expr,Literal,Operation,SourceSpan,EvalErrorandevaluate
Where to read next
- New to the library. Read getting started, then
the tutorial of the package you chose, for example the
binarytutorial or thedecimaltutorial. Keep numeric semantics open for the vocabulary. - Using it in an application or library. Read numeric semantics once, then work from the API pages of your packages. Before you rely on a standard behaviour, check the matching conformance page; for pipelines, read the tutorial of the checked wrapper.
- Contributing. Read architecture, verification and the repository conventions, then the design page of the package you change. Changes to an optimized path also need the performance audit and the package’s performance page.
Evidence snapshot
- The pinned GDA
officialcorpus passes 64,986/64,986 legal executable scalar rows, andofficial0passes 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.