programs/pathtrace's float contract and its math, written once over a float's operations: vectors, Newton sqrt, polynomial cis, constants
$ sexc add @ajax/pathtrace-math- total 3
- drwxr-xr-x-../
- drwxr-xr-x-Oct 27 01:59v/# 1 version
- drwxr-xr-x-Oct 27 01:59files/# the files of 0.1.0
- latest
- 0.1.0, published Oct 27 01:59 by ajax
- owners
- ajax
- license
- MIT
- dependencies
- none
- dependents
- @ajax/pathtrace-intersect, @ajax/pathtrace-sample, @ajax/pathtrace-tile, @ajax/pathtrace-tonemap
- keywords
- alphaos mesh pathtrace math determinism template
- homepage
- https://github.com/thomasdavis/alpha-c-mesh/tree/main/packages/pathtrace-math
- repository
- https://github.com/thomasdavis/alpha-c-mesh
1# @ajax/pathtrace-math 2 3The 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`. 8 9This 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`. 13 14**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`. 17 18## Differences 19 20- Generics become macros; Rust's tuple returns (`cis`) become out parameters.