<HTML> <HEAD> <TITLE>clamp</TITLE> <STYLE TYPE="text/css" MEDIA=screen> <!-- BODY { font-family: Arial,Helvetica; } BLOCKQUOTE { margin: 10pt; } H1,A { color: #336699; } /*** Top menu style ****/ .mmenuon { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #ff6600; font-size: 10pt; } .mmenuoff { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #ffffff; font-size: 10pt; } .cpyright { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #ffffff; font-size: xx-small; } .cpyrightText { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #ffffff; font-size: xx-small; } .sections { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: 11pt; } .dsections { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: 12pt; } .slink { font-family: Arial,Helvetica; font-weight: normal; text-decoration: none; color: #336699; font-size: 9pt; } .slink2 { font-family: Arial,Helvetica; text-decoration: none; color: #336699; } .maintitle { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: 18pt; } .dblArrow { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: small; } .menuSec { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: small; } .newstext { font-family: Arial,Helvetica; font-size: small; } .linkmenu { font-family: Arial,Helvetica; color: #000000; font-weight: bold; text-decoration: none; } P { font-family: Arial,Helvetica; } PRE { font-family: monospace; white-space: pre; font-color: #333333; font-weight: 100; background-color: #eeeeee; padding: 5px; width: 90%; border-style: solid; border-width: 2px; border-color: #bebebe; } .quote { font-family: Times; text-decoration: none; color: #000000; font-size: 9pt; font-style: italic; } .smstd { font-family: Arial,Helvetica; color: #000000; font-size: x-small; } .std { font-family: Arial,Helvetica; color: #000000; } .meerkatTitle { font-family: sans-serif; font-size: x-small; color: black; } .meerkatDescription { font-family: sans-serif; font-size: 10pt; color: black } .meerkatCategory { font-family: sans-serif; font-size: 9pt; font-weight: bold; font-style: italic; color: brown; } .meerkatChannel { font-family: sans-serif; font-size: 9pt; font-style: italic; color: brown; } .meerkatDate { font-family: sans-serif; font-size: xx-small; color: #336699; } .tocTitle { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #333333; font-size: 10pt; } .toc-item { font-family: Arial,Helvetica; font-weight: bold; color: #336699; font-size: 10pt; text-decoration: underline; } .perlVersion { font-family: Arial,Helvetica; font-weight: bold; color: #336699; font-size: 10pt; text-decoration: none; } .docTitle { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #000000; font-size: 10pt; } .dotDot { font-family: Arial,Helvetica; font-weight: bold; color: #000000; font-size: 9pt; } .docSec { font-family: Arial,Helvetica; font-weight: normal; color: #333333; font-size: 9pt; } .docVersion { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: 10pt; } .docSecs-on { font-family: Arial,Helvetica; font-weight: normal; text-decoration: none; color: #ff0000; font-size: 10pt; } .docSecs-off { font-family: Arial,Helvetica; font-weight: normal; text-decoration: none; color: #333333; font-size: 10pt; } h3 { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: small; } h2 { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: medium; } h1 { font-family: Verdana,Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: large; } DL { font-family: Arial,Helvetica; font-weight: normal; text-decoration: none; color: #333333; font-size: 10pt; } UL > LI > A { font-family: Arial,Helvetica; font-weight: bold; color: #336699; font-size: 10pt; } .moduleInfo { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #333333; font-size: 11pt; } .moduleInfoSec { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: 10pt; } .moduleInfoVal { font-family: Arial,Helvetica; font-weight: normal; text-decoration: underline; color: #000000; font-size: 10pt; } .cpanNavTitle { font-family: Arial,Helvetica; font-weight: bold; color: #ffffff; font-size: 10pt; } .cpanNavLetter { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #333333; font-size: 9pt; } .cpanCat { font-family: Arial,Helvetica; font-weight: bold; text-decoration: none; color: #336699; font-size: 9pt; } --> </STYLE> </HEAD> <BODY> <object type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e"> </object> <BLOCKQUOTE> <H1><A NAME="NAME"><A NAME="1">NAME </A></A></H1> <P> <B>clamp</B> - returns smallest integer not less than a scalar or each vector component. </P> <H1><A NAME="SYNOPSIS"><A NAME="2">SYNOPSIS </A></A></H1> <PRE> float clamp(float x, float a, float b); float1 clamp(float1 x, float1 a, float1 b); float2 clamp(float2 x, float2 a, float2 b); float3 clamp(float3 x, float3 a, float3 b); float4 clamp(float4 x, float4 a, float4 b); half clamp(half x, half a, half b); half1 clamp(half1 x, half1 a, half1 b); half2 clamp(half2 x, half2 a, half2 b); half3 clamp(half3 x, half3 a, half3 b); half4 clamp(half4 x, half4 a, half4 b); fixed clamp(fixed x, fixed a, fixed b); fixed1 clamp(fixed1 x, fixed1 a, fixed1 b); fixed2 clamp(fixed2 x, fixed2 a, fixed2 b); fixed3 clamp(fixed3 x, fixed3 a, fixed3 b); fixed4 clamp(fixed4 x, fixed4 a, fixed4 b); </PRE> <H1><A NAME="PARAMETERS"><A NAME="3">PARAMETERS </A></A></H1> <DL> <DT><STRONG>x </STRONG></DT> <DD> <P> Vector or scalar to clamp. </P> <DT><STRONG>a </STRONG></DT> <DD> <P> Vector or scalar for bottom of clamp range. </P> <DT><STRONG>b </STRONG></DT> <DD> <P> Vector or scalar for top of clamp range. </P> </DD></DL> <H1><A NAME="DESCRIPTION"><A NAME="4">DESCRIPTION </A></A></H1> <P> Returns <I>x</I> clamped to the range [<I>a</I>,<I>b</I>] as follows: </P> <DL> <DT><STRONG></STRONG></DT> <DD> <P> 1) Returns <I>a</I> if <I>x</I> is less than <I>a</I>; else </P> <DT><STRONG></STRONG></DT> <DD> <P> 2) Returns <I>b</I> if <I>x</I> is greater than <I>b</I>; else </P> <DT><STRONG></STRONG></DT> <DD> <P> 3) Returns <I>x</I> otherwise. </P> </DD></DL> <P> For vectors, the returned vector contains the clamped result of each element of the vector <I>x</I> clamped using the respective element of vectors <I>a</I> and <I>b</I>. </P> <H1><A NAME="REFERENCE_IMPLEMENTATION"><A NAME="5">REFERENCE IMPLEMENTATION </A></A></H1> <P> <B>clamp</B> for <B>float</B> scalars could be implemented like this. </P> <PRE> float clamp(float x, float a, float b) { return max(a, min(b, x)); } </PRE> <H1><A NAME="PROFILE_SUPPORT"><A NAME="6">PROFILE SUPPORT </A></A></H1> <P> <B>clamp</B> is supported in all profiles except <A HREF="fp20.html">fp20</A>. </P> <H1><A NAME="SEE_ALSO"><A NAME="7">SEE ALSO </A></A></H1> <P> <A HREF="max.html"><I>max</I></A>, <A HREF="min.html"><I>min</I></A>, <A HREF="saturate.html"><I>saturate</I></A> </P> </BLOCKQUOTE> </BODY>