1# @ajax/mesh-ref-gpt2-scalar
23GPT-2's scalar functions built only from `+ - * /` and integer bit operations, every float operation in
4the cluster float mode, so every executor (CPU, CUDA, Metal, wasm) computes the same bits: `exp` (range
5reduction by k·ln 2 in two parts, a degree-10 Horner polynomial, 2^k in two exact steps), `tanh` from it,
6the tanh-form GELU, and a Newton square root. The constants are f32 bit patterns.
78**Ported from** `crates/mesh-ref/src/gpt2.rs` (`exp_poly`, `tanh_poly`, `gelu_tanh`, `sqrt_newton`, the
9constants). Freestanding.
1011**Tested** by gpt2.rs's `constants_are_their_values` and `scalar_functions_are_close` (the double
12references computed without libm), and a golden digest from the Rust over 300 000 inputs of each
13function (random bits, tiny exponents, ±150).
1415## Differences
1617- `exp_poly` of a NaN: Rust's `as i32` turns NaN into 0, where a C cast is undefined, so it is tested
18 first and mapped to 0 as well.