---
title: "f32(): IR builder function in typeshade/core/ir, TypeShade"
description: "f32, an IR builder function in typeshade/core/ir. An f32 literal node."
url: https://typeshade.dev/api/f32/
language: en
---

# `f32()`

Function in Values

An `f32` literal node.

`import { f32 } from 'typeshade/core/ir'`

This export returns an IR node. A `"use typeshade"` file calls the builtin itself: [`f32()`](https://typeshade.dev/reference/functions/f32/)

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function f32(v: number): Node<'f32'>;
function f32(x: ReadonlyNode<ScalarCastSource>): Node<'f32'>;
```

## Parameters

**`v` `number`**

## Return value

`Node<'f32'>`

## Exceptions

**`TypeError`**

`v` is neither a JS number nor a scalar node.

**[`SD0116`](https://typeshade.dev/reference/errors/sd0116/)**

[`SD0116`](https://typeshade.dev/reference/errors/sd0116/) when the node operand is not a scalar.

## 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`](https://typeshade.dev/api/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

```ts
import { f32 } from 'typeshade/core/ir'

const half = f32(0.5)  // Node<'f32'>
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `f32(a)`. |
| GLSL ES 3.00 (WebGL2) | Supported | `float(a)`. |
| CPU oracle | Supported | Evaluated in `f64` by the oracle. |

## In the guide

- [Language guide](https://typeshade.dev/guide/internals/)
- [Your first shader](https://typeshade.dev/guide/internals/your-first-shader/)
- [Values and mutation](https://typeshade.dev/guide/internals/values-and-mutation/)
- [Layouts and resources](https://typeshade.dev/guide/internals/layouts-and-resources/)
- [Emitting and reflection](https://typeshade.dev/guide/internals/emitting-and-reflection/)
- [The CPU oracle](https://typeshade.dev/guide/internals/the-cpu-oracle/)
- [Diagnostics](https://typeshade.dev/guide/internals/diagnostics/)
- [Conditional programs](https://typeshade.dev/guide/internals/conditional-programs/)
- [fp64](https://typeshade.dev/guide/internals/fp64/)
- [Production emit](https://typeshade.dev/guide/internals/production-emit/)
- [Migrating a GLSL shader](https://typeshade.dev/guide/internals/migrating-a-glsl-shader/)

## See also

- [`f32()`](https://typeshade.dev/reference/functions/f32/)
- [`toF32`](https://typeshade.dev/api/tof32/)

## Source

[`src/core/ir/node.ts`, line 779](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/node.ts#L779), at commit af54ddad5
