1# @ajax/pathtrace-math
23The float contract of programs/pathtrace's renderer and its math. In Rust, `pathtrace-core` is written once
4over `R: Real` and instantiated with `f32` (the GPU) and mesh-ref's `Z` (CPUs). Here the renderer is
5written once in template headers over macros — `PT_ADD`, `PT_SUB`, `PT_MUL`, `PT_DIV`, `PT_NEG`, `PT_LT`,
6`PT_GT`, `PT_LE`, `PT_GE` and a name suffix `PT_SUFFIX` — and a translation unit instantiates it by
7defining them and including `pathtrace/instantiate.h` (`@ajax/pathtrace-tile`). Values are plain `float`.
89This package holds `pathtrace/real.h` (the contract), `pathtrace/consts.h` (the f32 bit constants,
10`pt_v`, bit casts) and `pathtrace/t_math.h` (vectors with the Rust's exact operation order, `sqrt` by
11three Newton steps from an integer guess, and `cis` by polynomial). Header only, freestanding; compile
12instantiations with `-ffp-contract=off`.
1314**Ported from** `crates/pathtrace-core/src/lib.rs` (`Real`, the constants, `V` and its operations,
15`sqrt`, `cis`). **Tested** in `@ajax/pathtrace-f32` and `-z`: 200 000 inputs against the Rust per float
16type, and the Rust's `sqrt_and_cis_are_close`.
1718## Differences
1920- Generics become macros; Rust's tuple returns (`cis`) become out parameters.