Name

clamp — constrain a value to lie between two further values

Declaration

genType clamp(genType  x,
 genType  minVal,
 genType  maxVal);
genType clamp(genType  x,
 float  minVal,
 float  maxVal);
genDType clamp(genDType  x,
 genDType  minVal,
 genDType  maxVal);
genDType clamp(genDType  x,
 double  minVal,
 double  maxVal);
genIType clamp(genIType  x,
 genIType  minVal,
 genIType  maxVal);
genIType clamp(genIType  x,
 int  minVal,
 int  maxVal);
genUType clamp(genUType  x,
 genUType  minVal,
 genUType  maxVal);
genUType clamp(genUType  x,
 uint  minVal,
 uint  maxVal);

Parameters

x

Specify the value to constrain.

minVal

Specify the lower end of the range into which to constrain x.

maxVal

Specify the upper end of the range into which to constrain x.

Description

clamp returns the value of x constrained to the range minVal to maxVal. The returned value is computed as min(max(x, minVal), maxVal).

Version Support

FunctionVersion 1.10Version 1.20Version 1.30Version 1.40Version 1.50Version 3.30Version 4.00Version 4.10Version 4.20Version 4.30
clamp (genType)YYYYYYYYYY
clamp (genIType)--YYYYYYYY
clamp (genUType)--YYYYYYYY
clamp (genDType)------YYYY

See Also

min, max

Copyright

Copyright © 2011 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.