Arbitrary-precision binary, decimal, and ball arithmetic for MoonBit, with checked operations and explicit numeric semantics.
Dependencies
moon add Luna-Flow/floating@0.9.0import {
"Luna-Flow/floating/bin_float",
"Luna-Flow/floating/decimal",
"Luna-Flow/floating/ball_float",
}///|
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")
}| Package | Purpose | Result model |
|---|---|---|
| bin_float | arbitrary-precision binary floating point, IEEE 754 binary operations, binary16/32/64/128 interchange | value, or (value, BinaryFlags) under a BinaryContext |
| decimal | IEEE 754 decimal arithmetic, decimal32/64/128 DPD and BID interchange | value, or (value, DecimalFlags) under a DecimalContext |
| decimal_gda | General Decimal Arithmetic with sticky status and traps | GdaOutcome with the defined result and the next context |
| ball_float | outward-rounded bare and decorated intervals (IEEE 1788) | interval, or (interval, BallFlags) under a BallContext |
| bin_float_checked | binary pipeline that stops at the first error | Result[BinFloat, ArithmeticError] in a wrapper |
| decimal_checked | IEEE decimal pipeline that accumulates flags | value with latest and accumulated flags |
| decimal_gda_checked | GDA pipeline that stops at a trap | one threaded GdaOutcome |
| ball_float_checked | interval pipeline that stops at the first error | Result[BallFloat, ArithmeticError] in a wrapper |
| def | shared vocabulary: Sign, PartialOrder, the Floating trait | — |
| semantic | exact projection for comparing values across packages | exact rational, signed infinity or NaN |
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 releasejust conformance smoke binary
just conformance run decimal --run-target native --run-target wasm
just conformance run interval --phase trigonometric --strict-supportedInstall
Download zipArbitrary-precision binary, decimal, and ball arithmetic for MoonBit, with checked operations and explicit numeric semantics.
Dependencies