This documentation tracks the current repository baseline for v0.3.0.
It describes the implementation that exists in this branch today.
def:floating-local support such asSign,PartialOrder, and the narrowFloatingtrait, plus compatibility reexports for arithmetic-boundary types.bin_float: Arbitrary-precision binary floating-point values represented by significand, base-2 exponent, and working precision.decimal: Arbitrary-precision decimal floating-point values represented by coefficient, base-10 exponent, and working precision.ball_float: Interval/ball arithmetic values represented by outward-rounded bounds, built on top ofbin_float.bin_float_result:Result[BinFloat, ArithmeticError]wrapped as a closed numeric object for checked composition.decimal_result:Result[Decimal, ArithmeticError]wrapped as a closed numeric object for checked composition.ball_float_result:Result[BallFloat, ArithmeticError]wrapped as a closed interval object for checked composition.internal: Shared normalization, integer-factor removal, rounding, and decimal parsing helpers.consistency: Repository tests covering normalization, conversion, arithmetic, and cross-package semantic alignment.
- Capability-boundary integration:
floatingnow depends onLuna-Flow/arithmeticfor shared arithmetic boundary types and checked capability traits. - Shared floating support:
defkeepsSign,PartialOrder, and the repository-wideFloatingtrait while reexporting arithmetic-boundary types for compatibility. - Two scalar arbitrary-precision representations:
bin_floatanddecimalexpose constructors, normalization, precision control, formatting/parsing, comparison, and basic arithmetic. - Ball arithmetic baseline:
ball_floatsupports exact embedding, overlap/containment predicates, outward-rounded interval arithmetic, checked integer power, and whole-real fallback for division by zero-containing divisors. - Result-wrapped endomorphism layer:
bin_float_result,decimal_result, andball_float_resultlift checked arithmetic intoSelf -> Selfand(Self, Self) -> Selfcomposition over wrappedResultvalues. - Cross-representation conversion:
decimalconverts to and frombin_float;ball_floatembeds exactbin_floatvalues. - Correctness-first tests: the repository includes whitebox tests for normalization, arithmetic, conversion behavior, and interval-enclosure edge cases.
- Modern Moon package metadata: the repository uses
moon.modas the canonical module manifest.
Floatingis intentionally small: it covers classification, sign, precision, precision retuning, and normalization rather than every numeric operation.- Checked operations come from
arithmetic:BinFloatandDecimalimplement checked scalar traits such asSqrtChecked,DivChecked,CompareChecked,PowNatChecked,PowIntChecked, andParseCheckedwhere valid. BallFloatstays enclosure-first: it implements enclosure relations plus checked division and checked integer power, but it does not pretend to be a totally ordered scalar.- Result wrappers stay closed under composition: each
*_resultpackage providesok,err,from_result,result,map,bind,flat_map, and lifted numeric operations returning the same wrapper type. - Observer APIs stay separate from endomorphisms: operations such as checked comparison still naturally return non-
Selfvalues and are not forced into the closed wrapper algebra. - Normalization is part of the contract: public constructors normalize finite values to canonical internal forms.
- Precision changes are explicit: use
with_precision(..., mode)to request a different working precision. - Ball semantics are enclosure-oriented:
ball_floatexposes overlap and containment style relations rather than pretending all values are totally ordered. - Enclosure correctness beats narrowness: interval results may widen around branch cuts or ambiguous domains rather than returning an unsound narrow band.
BallFloatResultpreserves enclosure fallback semantics: division by an interval containing zero remains a whole-real enclosure, while invalid wrapper construction is represented asErr.- Repository docs describe the current code: if an API is not present in this branch, it is not part of this release baseline.
- Arbitrary-precision binary values: normalized finite values,
nan,inf, comparison,ulp, checked arithmetic helpers,sqrt, andpow_int. - Arbitrary-precision decimal values: string parsing, normalized display, precision-aware arithmetic, binary conversion, and checked arithmetic helpers.
- Ball arithmetic baseline: exact balls, interval bounds,
contains,overlaps,separated_from,definitely_lt,definitely_le,maybe_eq, and outward-rounded interval arithmetic. - Checked composition wrappers: closed
Result-wrapped arithmetic for binary, decimal, and ball values with explicit short-circuiting error propagation. - No upper-layer mathematics in this pass: no transcendental layer, calculus, matrices, complex numbers, symbolic APIs, or special functions are reintroduced here.
- Shared rounding helpers: internal support for factor stripping, decimal parsing, and rounding to requested precision.
- Consistency tests: cross-package tests verify normalization, exact dyadic behavior, decimal parsing, binary-decimal conversion, checked error paths, and ball enclosure correctness.
let x = @bin_float.BinFloat::make(3N, -1, 32)
let y = @bin_float.BinFloat::make(5N, -1, 32)
let sum = x + y
let dec = @decimal.Decimal::from_string("12.34", precision=32).unwrap()
let as_bin = dec.to_bin_float(precision=32)
let exact_ball = @ball_float.BallFloat::exact(as_bin)
let other_ball = @ball_float.BallFloat::from_bounds(
@bin_float.BinFloat::make(3N, 0, 32),
@bin_float.BinFloat::make(7N, 0, 32),
precision=32,
)
inspect(sum.to_string(), content="1p2")
inspect(exact_ball.contains(as_bin).to_string(), content="true")
inspect(other_ball.definitely_lt(@ball_float.BallFloat::from_int(10, precision=32)).to_string(), content="true")
let checked =
@decimal_result.DecimalResult::parse("9.0", precision=32)
.sqrt()
.div(@decimal_result.DecimalResult::from_int(3, precision=32))
inspect(checked.result().unwrap().to_string(), content="1")We provide documentation in multiple languages:
- 🇺🇸 English (
doc/en_US) - 🇨🇳 简体中文 (
doc/zh_CN) - 🇯🇵 日本語 (
doc/ja_JP)
Package documentation:
Localized README files:
Useful local commands:
moon fmt
moon check
moon test
moon test --enable-coverageThe repository test baseline currently lives in src/consistency and is run by moon test.
Before triggering the publish workflow:
- Bump
moon.modto the intended release version. - Update
README.mdand localized docs so they match the current repository state. - Run
moon checkandmoon test. - Trigger
publish-package; it reads the release version directly frommoon.mod.
If the workflow reports a duplicate version, the package manager already contains that version and a new version bump is required.
Contribution guidance is available in CONTRIBUTING.md.