consistency design
Design goal
floating has four numeric cores with overlapping claims: a binary value
converted to a decimal and back must denote the same rational number; the
checked wrappers must give the same values as the cores; an interval must
enclose the exact result of the scalar operation; all cores must round
through the same internal rules. Each package’s own tests cannot see the
others. consistency is the one place where these cross-package laws are
written down and executed.
Mathematical background
Every finite value of every core denotes a rational number. Let
map a value to (implemented by
semantic, with internal.ExactRat as canonical form). The laws the suite
checks have three shapes:
- Agreement: for values of package and of package that represent the same input, when both operations are exact, and the results are the two packages’ roundings of the same real otherwise.
- Exact oracles: a helper or operation equals a
BigIntor rational computation, for exampleround_positive_divagainst plus the rounding table, ordigits10against powers of ten. - Enclosure: for an interval operation and a point operation , , and enclosure relations behave as partial orders rather than total orders.
Representation laws are checked as well: GDA results keep the right cohort, signed zero and NaN payload; interchange encodings round-trip bit for bit.
Design decisions
White-box tests only
The package has no source files besides tests, and imports the cores only
for "wbtest". It therefore never becomes part of a library build and has
no API to maintain, while still being able to use internal helpers.
Fixed witnesses from official corpora
Many decimal tests use rows of the official decTest suite as named witnesses. They pin the exact cases that once disagreed between packages, in-process and without the corpus download.
Oracles over expectations
Where possible a test computes the expected result independently (with
BigInt, ExactRat or semantic) instead of hard-coding output strings, so
a law stays meaningful when formatting changes.
Correctness / invariants
- A passing run shows that each stated law holds on its witnesses; it is finite evidence, not a proof for all inputs.
- Tests are deterministic and target-independent, so the same run on native, Wasm and JavaScript checks the same claims.
Alternatives rejected
- Putting cross-package tests into each package. It would create test-only dependency cycles between the cores.
- Property-based random testing only. Random inputs rarely hit cohort boundaries and ties; fixed witnesses do.
Boundaries
- No public API and no runtime code.
- No external corpora (that is the role of the conformance frontends) and no
performance measurements (the
benchpackages).