---
title: "fract(): IR builder function in typeshade/core/ir, TypeShade"
description: "fract, an IR builder function in typeshade/core/ir. fract(x): fractional part, x − floor(x), component-wise."
url: https://typeshade.dev/api/fract/
language: en
---

# `fract()`

Function in Builtins

`fract(x)`: fractional part, x − `floor(x)`, component-wise.

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

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

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

## Syntax

```ts
const fract: <K extends FloatKey | Float64Key>(
  x: ReadonlyNode<K>,
) => Node<K>
```

## Parameters

**`x` `ReadonlyNode<K>`**

## Return value

`Node<K>`

## Description

The building block for domain repetition (tiling a coordinate into `[0, 1)`) and for hash-style noise such as `fract(dot(p3, p3.yzx.add(33.33)))`.

## Examples

### Example

```ts
import { fn, fract, f32T } from 'typeshade/core/ir'

const wrap = fn('wrap', { x: f32T }, ({ x }) => fract(x))
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `fract(x)`. Over `f64` operands the fp64 pass rewrites it into its `df64` helper. |
| GLSL ES 3.00 (WebGL2) | Supported | `fract(x)`. Over `f64` operands the fp64 pass rewrites it into its `df64` helper. |
| CPU oracle | Supported | Evaluated in `f64` by the oracle. |

## In the guide

- [Functions and entry points](https://typeshade.dev/guide/internals/functions-and-entry-points/)
- [fp64](https://typeshade.dev/guide/internals/fp64/)

## See also

- [`fract()`](https://typeshade.dev/reference/functions/fract/)

## Source

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