clamp

Description

Clamp. Returns the specified value clamped to the specified minimum and maximum bounds.

Signature

/// Requires Capability Set 1:
T clamp<T>(
    T x,
    T minBound,
    T maxBound)
    where T : __BuiltinIntegerType;

/// Requires Capability Set 1:
vector<T, N> clamp<T, int N>(
    vector<T, N> x,
    vector<T, N> minBound,
    vector<T, N> maxBound)
    where T : __BuiltinIntegerType;

/// Requires Capability Set 1:
matrix<T, N, M> clamp<T, int N, int M>(
    matrix<T, N, M> x,
    matrix<T, N, M> minBound,
    matrix<T, N, M> maxBound)
    where T : __BuiltinIntegerType;

/// Requires Capability Set 1:
T clamp<T>(
    T x,
    T minBound,
    T maxBound)
    where T : __BuiltinFloatingPointType;

/// Requires Capability Set 1:
vector<T, N> clamp<T, int N>(
    vector<T, N> x,
    vector<T, N> minBound,
    vector<T, N> maxBound)
    where T : __BuiltinFloatingPointType;

/// Requires Capability Set 1:
matrix<T, N, M> clamp<T, int N, int M>(
    matrix<T, N, M> x,
    matrix<T, N, M> minBound,
    matrix<T, N, M> maxBound)
    where T : __BuiltinFloatingPointType;

/// Requires Capability Set 2:
CoopVec<T, N> clamp<T, int N>(
    CoopVec<T, N> x,
    CoopVec<T, N> minVal,
    CoopVec<T, N> maxVal)
    where T : __BuiltinFloatingPointType;

/// Requires Capability Set 2:
CoopVec<T, N> clamp<T, int N>(
    CoopVec<T, N> x,
    CoopVec<T, N> minVal,
    CoopVec<T, N> maxVal)
    where T : __BuiltinIntegerType;

Generic Parameters

T: __BuiltinIntegerType

N : int

M : int

T: __BuiltinFloatingPointType

Parameters

x : T

The value to clamp.

minBound : T

The minimum bound.

maxBound : T

The maximum bound.

x : vector<T, N>

The value to clamp.

minBound : vector<T, N>

The minimum bound.

maxBound : vector<T, N>

The maximum bound.

x : matrix<T, N, M>

The value to clamp.

minBound : matrix<T, N, M>

The minimum bound.

maxBound : matrix<T, N, M>

The maximum bound.

x : CoopVec<T, N>

The value to clamp.

minVal : CoopVec<T, N>

maxVal : CoopVec<T, N>

Return value

The clamped value.

Availability and Requirements

Capability Set 1

Defined for the following targets:

hlsl

Available in all stages.

glsl

Available in all stages.

cpp

Available in all stages.

cuda

Available in all stages.

metal

Available in all stages.

wgsl

Available in all stages.

spirv

Available in all stages.

llvm

Available in all stages.

Capability Set 2

Defined for the following targets:

hlsl

Available in all stages.

glsl

Available in all stages.

cpp

Available in all stages.

cuda

Available in all stages.

spirv

Available in all stages.

Requires capability: spvCooperativeVectorNV.