--- layout: stdlib-reference --- # 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, N:int>(
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, N:int, M:int>(
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, N:int>(
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, N:int, M:int>(
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, N:int>(
CoopVec<T, N> x,
CoopVec<T, N> minVal,
CoopVec<T, N> maxVal)
where T : __BuiltinFloatingPointType;
/// Requires Capability Set 2:
CoopVec<T, N> clamp<T, N:int>(
CoopVec<T, N> x,
CoopVec<T, N> minVal,
CoopVec<T, N> maxVal)
where T : __BuiltinIntegerType;
## Generic Parameters
#### T: [\_\_BuiltinIntegerType](../interfaces/0_builtinintegertype-029g/index.html)
#### N : int
#### M : int
#### T: [\_\_BuiltinFloatingPointType](../interfaces/0_builtinfloatingpointtype-029hm/index.html)
## Parameters
#### x : [T](clamp.html#typeparam-T)
The value to clamp.
#### minBound : [T](clamp.html#typeparam-T)
The minimum bound.
#### maxBound : [T](clamp.html#typeparam-T)
The maximum bound.
#### x : [vector](../types/vector/index.html)\<[T](../types/vector/index.html#typeparam-T), [N](../types/vector/index.html#decl-N)\>
The value to clamp.
#### minBound : [vector](../types/vector/index.html)\<[T](../types/vector/index.html#typeparam-T), [N](../types/vector/index.html#decl-N)\>
The minimum bound.
#### maxBound : [vector](../types/vector/index.html)\<[T](../types/vector/index.html#typeparam-T), [N](../types/vector/index.html#decl-N)\>
The maximum bound.
#### x : [matrix](../types/matrix/index.html)\<[T](../types/matrix/t-0.html), [N](../types/matrix/index.html#decl-N), [M](../types/matrix/index.html#decl-M)\>
The value to clamp.
#### minBound : [matrix](../types/matrix/index.html)\<[T](../types/matrix/t-0.html), [N](../types/matrix/index.html#decl-N), [M](../types/matrix/index.html#decl-M)\>
The minimum bound.
#### maxBound : [matrix](../types/matrix/index.html)\<[T](../types/matrix/t-0.html), [N](../types/matrix/index.html#decl-N), [M](../types/matrix/index.html#decl-M)\>
The maximum bound.
#### x : [CoopVec](../types/coopvec-04/index.html)\<[T](../types/coopvec-04/index.html#typeparam-T), [N](../types/coopvec-04/index.html#decl-N)\>
The value to clamp.
#### minVal : [CoopVec](../types/coopvec-04/index.html)\<[T](../types/coopvec-04/index.html#typeparam-T), [N](../types/coopvec-04/index.html#decl-N)\>
#### maxVal : [CoopVec](../types/coopvec-04/index.html)\<[T](../types/coopvec-04/index.html#typeparam-T), [N](../types/coopvec-04/index.html#decl-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.
### Capability Set 2
Defined for the following targets:
#### hlsl
Available in all stages.
Requires capability: `hlsl_coopvec_poc`.
#### cpp
Available in all stages.
#### cuda
Available in all stages.
#### spirv
Available in all stages.
Requires capability: `spvCooperativeVectorNV`.