MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / formatFloat

Function formatFloat

src/compute-engine/compilation/constant-folding.ts:22–36  ·  view source on GitHub ↗
(n: number)

Source from the content-addressed store, hash-verified

20/**
21 * The shader spelling of a NON-FINITE value (`NaN`, `±∞`).
22 *
23 * Neither GLSL nor WGSL has a `NaN` or an `Infinity` LITERAL — but both can
24 * MAKE those values from a bit pattern, and the GPU target already routes the
25 * masked (`When` / `Which` fall-through) NaN through exactly that mechanism
26 * (`gpuNaN` in `gpu-target.ts`, which delegates here so there is exactly one
27 * spelling). A non-finite CONSTANT is the same value reached by another route,
28 * so it gets the same spelling instead of failing the compilation.
29 *
30 * GLSL goes through the overridable preamble helpers `_gpu_nan()` /
31 * `_gpu_inf()` — one symbol a host can redefine without touching the generated
32 * code. WGSL uses an inline `bitcast`, matching the existing WGSL NaN
33 * convention (its spelling is pinned by `compile-wgsl.test.ts`).
34 *
35 * Infinity is a BIT PATTERN, never `1.0 / 0.0`: a fast-math driver is licensed
36 * to fold a division by a constant zero (ANGLE→Metal fast-math already
37 * destroys compensated arithmetic in this project), and a bit pattern is not
38 * foldable.
39 */

Callers 4

gpu-target.tsFile · 0.90
foldTermsFunction · 0.85
tryGetComplexPartsFunction · 0.85

Calls 2

toStringMethod · 0.65
isFiniteMethod · 0.45

Tested by

no test coverage detected