Arithmetic capability traits and checked or contextual numeric boundaries for Luna Flow projects.
This release expands the contextual capability boundary built in 0.3.0 and
the certification-failure vocabulary added in 0.4.0. The new traits cover
integer embedding, adjacent representable values, context-dependent constants,
and context-dependent hyperbolic functions without bundling unrelated numeric
requirements.
For earlier release notes and repository history, see CHANGELOG.md.
IntegralContextualembeds a MoonBitIntunder an explicit context and returns conversion diagnostics.AdjacentContextualexposes next-plus, next-minus, and next-toward operations while preserving signed-zero and infinity boundaries.ConstantsContextualandHyperbolicContextualdefine context-faithful outcome surfaces for numeric backends that can report meaningful diagnostics.- Proof-backed constant implementations can preserve target-rounding failures
through
ArithmeticErrorKind::CertificationFailure.
luna-genericexpresses algebraic structure such asRing,Field, andNum.arithmeticexpresses analytic functions, checked operations, contextual outcomes, and enclosure-style relations.- The package describes small capabilities rather than declaring a bundled “real number” abstraction.
- Concrete numeric packages should implement only the traits whose semantics they can support faithfully.
Sqrt,Cbrt,RadicalExponential,Logarithmic,PowerTrigonometric,InverseTrigonometricHyperbolic,InverseHyperbolicConstants
These traits preserve direct backend behavior and return Self.
SqrtChecked,DivChecked,CompareCheckedPowNatChecked,PowIntChecked,ParseChecked
Checked traits return Result[..., ArithmeticError] and use
ArithmeticContext where the operation needs an explicit context.
ArithmeticError can also carry a CertificationFailureDetail when a
proof-backed backend cannot certify a result at the requested target.
AddContextual,SubContextual,MulContextual,DivContextualAbsContextual,SqrtContextual,ExpContextualIntegralContextual,AdjacentContextualConstantsContextual,HyperbolicContextualNumericFormatContextual
Contextual operations return ArithmeticOutcome[Self] inside Result, keeping
the computed value and diagnostic flags together as immutable data.
Contains,OverlapsDefinitelyLt,DefinitelyLe,MaybeEq
These traits model containment and definite or possible relations without pretending enclosure values form a scalar total order.
ArithmeticContext::newclamps precision to at least1.- If both exponent limits are present,
e_minmust not exceede_max. - The decimal presets use precisions
7,16, and34with their matching exponent ranges and clamping enabled. ArithmeticDiagnostics::combinemerges flags with logical OR, so callers can aggregate a sequence of outcomes explicitly.
The built-in Float and Double contextual implementations do not emulate
arbitrary decimal precision, directed rounding, exponent clamping, or general
IEEE status-flag detection. Contextual division and square root delegate
validation to their checked counterparts. Integer embedding reports
inexact/rounded when conversion to Float loses information. Adjacent
operations use the fixed IEEE binary format and treat selecting the neighboring
value as exact. Float and Double intentionally do not implement
ConstantsContextual or HyperbolicContextual, because their native functions
cannot honor arbitrary contexts or report complete diagnostics.
moon add Luna-Flow/arithmetic@0.5.0
moon add Luna-Flow/luna-generic@0.3.1Use explicit Luna Flow aliases in moon.pkg:
import {
"Luna-Flow/luna-generic" @lf_alg,
"Luna-Flow/arithmetic" @lf_arith,
}using @lf_alg { trait Add, trait Mul }
using @lf_arith { trait Sqrt }
fn hypot2[T : Add + Mul + Sqrt](x : T, y : T) -> T {
Sqrt::sqrt(x * x + y * y)
}
let context = @lf_arith.ArithmeticContext::decimal64()
let outcome = @lf_arith.DivContextual::div_contextual(10.0, 4.0, context).unwrap()
inspect(outcome.value, content="2.5")
inspect(outcome.diagnostics.inexact, content="false")- English: doc/en_US/README.md
- Simplified Chinese: doc/zh_CN/README.md
- Japanese: doc/ja_JP/README.md
- Getting started: doc/en_US/getting_started.md
- Architecture: doc/en_US/architecture.md
- Verification: doc/en_US/verification.md
- Documentation standard: doc/en_US/doc_standard.md
Historical release notes live in CHANGELOG.md. This README stays focused on the current package baseline and entry points.
Useful local commands:
moon fmt
moon info
moon check --target all
moon test- Bump
moon.modto the intended release version. - Update
README.md, all three localized documentation trees, andCHANGELOG.md. - Run
moon fmt --check,moon info,moon build --target all,moon check --target all --frozen, and the default, JavaScript, and native test suites. - Trigger
publish-packagewith the exactmoon.modversion. The workflow repeats the checks, publishes to mooncakes, and creates the matching GitHub release.
The workflow publishes the version declared in moon.mod to mooncakes; it does
not accept a mismatched release version.