floating

    Arbitrary-precision binary, decimal, and interval arithmetic for MoonBit, with checked operations and explicit numeric semantics.

    floating-point
    arbitrary-precision
    decimal
    interval
    ieee-754
    Download zip
    Author
    Version
    0.12.0-pre
    License
    Apache-2.0
    Last updated
    2 days ago
    Downloads
    367

    #floating

    Maintainer License State

    Luna-Flow/floating provides arbitrary-precision binary, IEEE decimal, General Decimal Arithmetic, and certified interval arithmetic for MoonBit. Binary values follow IEEE 754 at any precision, decimals keep their exponent, and intervals are rounded outward so that they always contain the exact result. Precision, rounding, exponent range, special values, status flags, traps and enclosures are explicit values in every API rather than hidden global state.

    #Install

    moon add Luna-Flow/floating@0.11.0

    The module needs the MoonBit toolchain with moonc 0.10.20 or later (verified with moon 0.1.20261104 and moonc v0.10.20; older 0.10 compilers ignore #derive). Import only the packages you use in your moon.pkg:

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

    #Quick start

    ///|
    test "floating quick start" {
    // One third, correctly rounded to binary64, with its IEEE status.
    let ctx = @binary.BinaryContext::binary64()
    let (third, flags) = @binary.Binary::from_int(1).div_ctx(
    @binary.Binary::from_int(3),
    ctx,
    )
    inspect(third.to_shortest_string(), content="0.3333333333333333")
    inspect(flags.inexact(), content="true")

    // A decimal keeps the exponent of its literal.
    let (price, _) = @decimal.Decimal::from_string_ctx(
    "12.3400",
    @decimal.DecimalContext::decimal64(),
    )
    inspect(price.exponent10(), content="-4")

    // An interval contains every exact result.
    let one = @interval.Interval::from_int(1, precision=53)
    let enclosure = one.div(@interval.Interval::from_int(3, precision=53))
    inspect(enclosure.contains(third), content="true")
    }

    The three results have different contracts: third is one rounded point with the flags its rounding raised, price retains the exponent -4 of 12.3400, and enclosure is a set of reals guaranteed to contain .

    #Packages

    PackagePurposeResult model
    binaryarbitrary-precision binary floating point, IEEE 754 binary operations, binary16/32/64/128 interchangevalue, or (value, BinaryFlags) under a BinaryContext
    decimalIEEE 754 decimal arithmetic, decimal32/64/128 DPD and BID interchangevalue, or (value, DecimalFlags) under a DecimalContext
    decimal_gdaGeneral Decimal Arithmetic with sticky status and trapsGdaOutcome with the defined result and the next context
    intervaloutward-rounded bare and decorated intervals (IEEE 1788)interval, or (interval, IntervalFlags) under an IntervalContext
    binary_checkedbinary pipeline that stops at the first errorResult[Binary, ArithmeticError] in a wrapper
    decimal_checkedIEEE decimal pipeline that accumulates flagsvalue with latest and accumulated flags
    decimal_gda_checkedGDA pipeline that stops at a trapone threaded GdaOutcome
    interval_checkedinterval pipeline that stops at the first errorResult[Interval, ArithmeticError] in a wrapper
    defshared vocabulary: Sign, PartialOrder, the Floating trait—

    Expression, corpus-frontend, CLI, benchmark and differential-testing packages are not part of this module: they live in the separate module Luna-Flow/floating-tools of the same repository, next to the library. The package map lists every package with its tutorial, API and design pages; internal and internal/decimal_kernel stay in this module as repository infrastructure.

    #Documentation

    The manual is published at https://lunaflow.cn/en/floating/ in English, Chinese and Japanese; its English source is in doc/manual. Good starting points:

    • Getting started: choosing a package and first programs.
    • Numeric semantics: rounding, ulp, flags, exponent, signed zero, NaN and enclosures.
    • Architecture: layers, the numeric core pipeline and certified elementary functions.
    • Verification: gates and the scope of every conformance claim.

    Conformance evidence is finite and pinned: the GDA official corpus passes 64,986/64,986 legal executable rows, the binary TestFloat level-1 matrix 254,227,872 vectors, and the strict ITF1788 aggregate 4,656/4,656 cases. Read the conformance pages before turning a result into a compatibility claim.

    #Stability

    The public API of every package follows the changelog of each release. Floating in def is implemented by the types of this library only; implementing it for a type outside this module is not supported and not covered by the compatibility promise, because methods may be added to the trait in a minor release.

    #Development

    The repository (Luna-Flow/floating) holds this module in library/, the tools module in tooling/, the manual, the pinned corpora and the gate scripts. The task runner, the gates and the conformance entry points are described in the repository README and in CONTRIBUTING; the corpora are documented under testdata.

    #Contributing

    Contributions to correctness, documentation and test coverage are welcome. Read CONTRIBUTING for the workflow and the repository conventions for documentation and API snapshot rules. Release history is in CHANGELOG.

    #License

    Apache-2.0. See LICENSE.