f32()
Function in Values
An f32 literal node.
import { f32 } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function f32(v: number): Node<'f32'>;function f32(x: ReadonlyNode<ScalarCastSource>): Node<'f32'>;Parameters
vnumber
Return value
Node<'f32'>
Exceptions
Description
Most bare-number operands lift to f32 on their own (x.add(1) emits
+ 1.0 for an f32 x), so this is needed only where a standalone f32 value is wanted
outside an operand position: a module-level const, a default argument.
A Node argument is a cast instead, the spelling WGSL and the "use typeshade" surface both
write: f32(i) converts, and is the free-function twin of i.f32(). It builds what
toF32 builds, so the two spellings share one emit. The operand is bounded to a
scalar, which closes a hole both surfaces had: f32(someVec3) type-checked and emitted
f32(v), which no target compiles.
Examples
Example
import { f32 } from 'typeshade'
const half = f32(0.5) // Node<'f32'>Targets
| Target | Support | Notes |
|---|---|---|
| WGSL (WebGPU) | Supported |
|
| GLSL ES 3.00 (WebGL2) | Supported |
|
| CPU oracle | Supported | Evaluated in f64 by the oracle. |
In the guide
See also
Source
src/core/ir/node.ts, line 968, at commit 26de7be8