1# @ajax/wasm-numeric
23WebAssembly's numeric instructions (spec §4.3) as C functions, deterministic across machines: integer
4division and remainder with their traps, rotates and the arithmetic right shift without undefined
5behaviour, bit counts, float min/max with the spec's NaN and signed-zero rules, `nearest` as
6ties-to-even, trapping float-to-integer truncation with the exact bounds (NaN is "invalid conversion to
7integer", out of range "integer overflow"), and the saturating ones.
89As meshd's wasmtime engine is configured (`cranelift_nan_canonicalization(true)` in alpha-rust-mesh's
10`mesh-host/src/wasm.rs`, so NaN bits are the same on x86 and arm), every NaN an arithmetic operation
11produces is the canonical one (0x7fc00000 / 0x7ff8000000000000): add, sub, mul, div, sqrt, min, max,
12ceil, floor, trunc, nearest, promote and demote. `neg`, `abs` and `copysign` are bit operations and keep
13payloads. Trap codes are numbered as wasmtime's `Trap`, because meshd reports them in its FAULT_TRAP
14word. Build users with `-ffp-contract=off` (no fused multiply-add). Header-only.
1516Tests: `tests/numeric.c`.