Sign in

    floating

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

    floating-point
    arbitrary-precision
    decimal
    interval
    ieee-754
    Download zip
    Author
    Version
    0.9.0
    License
    Apache-2.0
    Last updated
    5 hours ago
    Downloads
    101

    #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 quantum, 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.9.0

    The module needs the MoonBit toolchain 0.10 or later (moonc ≥ 0.10). Import only the packages you use in your moon.pkg:

    import {
    "Luna-Flow/floating/bin_float",
    "Luna-Flow/floating/decimal",
    "Luna-Flow/floating/ball_float",
    }

    #Quick start

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

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

    // An interval contains every exact result.
    let one = @ball_float.BallFloat::from_int(1, precision=53)
    let enclosure = one.div(@ball_float.BallFloat::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 quantum -4 of 12.3400, and enclosure is a set of reals guaranteed to contain .

    #Packages

    PackagePurposeResult model
    bin_floatarbitrary-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
    ball_floatoutward-rounded bare and decorated intervals (IEEE 1788)interval, or (interval, BallFlags) under a BallContext
    bin_float_checkedbinary pipeline that stops at the first errorResult[BinFloat, 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
    ball_float_checkedinterval pipeline that stops at the first errorResult[BallFloat, ArithmeticError] in a wrapper
    defshared vocabulary: Sign, PartialOrder, the Floating trait—
    semanticexact projection for comparing values across packagesexact rational, signed infinity or NaN

    Expression, corpus-frontend, CLI, benchmark, consistency and internal/* packages are repository infrastructure. The package map lists all of them with their tutorial, API and design pages.

    #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, quantum, 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.

    #Development

    The repository uses just as its task runner.

    just pr 8 # pull-request gate just fmt # format MoonBit sources just docs # manual checks and documentation examples just gate binary 8 # TestFloat and MPFR just gate decimal 8 # IEEE decimal vectors just gate decimal_gda 8 # GDA decTest corpora just gate interval 8 # strict ITF1788 just ci 8 # everything, before a release

    Smoke fixtures, plans, pinned corpora, targets and phases go through one entry point:

    just conformance smoke binary just conformance run decimal --run-target native --run-target wasm just conformance run interval --phase trigonometric --strict-supported

    Corpus provenance and options are described in testdata/bin_float, testdata/decimal and testdata/interval.

    #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.