abs
On this page

abs()

Function in Builtins

abs(x): absolute value, component-wise.

import { abs } from 'typeshade'

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

Syntax

const abs: <K extends FloatKey | Float64Key | IntKey>(
x: ReadonlyNode<K>,
) => Node<K>

Parameters

x ReadonlyNode<K>

Return value

Node<K>

Description

An unsigned operand takes the absU id rather than the portable abs one, because GLSL ES 3.00 has no abs(uint) overload and a WebGL2 driver refuses the call. The choice is divergentIntegerId, shared with the "use typeshade" front end so both authoring surfaces emit the same thing; every other operand keeps the portable spelling.

Examples

Example

import { fn, abs, f32T } from 'typeshade'
const magnitude = fn('magnitude', { x: f32T }, ({ x }) => abs(x))

Targets

TargetSupportNotes
WGSL (WebGPU) Supported

abs(a). Over f64 operands the fp64 pass rewrites it into its df64 helper.

GLSL ES 3.00 (WebGL2) Supported

abs(a). Over f64 operands the fp64 pass rewrites it into its df64 helper.

CPU oracle Supported

Evaluated in f64 by the oracle.

In the guide

Source

src/core/ir/node.ts, line 1472, at commit 26de7be8

Edit this page Report a problem