sign
Keywords: sign, NVIDIA, NVIDIA Cg Toolkit, Cg Toolkit, Shader, Shader Programming, GPU Shader Programming, GPU Program

> ## Name

> sign - returns sign of scalar or each vector component.

> ## Synopsis

>     float  sign(float x);
>     float1 sign(float1 x);
>     float2 sign(float2 x);
>     float3 sign(float3 x);
>     float4 sign(float4 x);

>     half   sign(half x);
>     half1  sign(half1 x);
>     half2  sign(half2 x);
>     half3  sign(half3 x);
>     half4  sign(half4 x);

>     fixed  sign(fixed x);
>     fixed1 sign(fixed1 x);
>     fixed2 sign(fixed2 x);
>     fixed3 sign(fixed3 x);
>     fixed4 sign(fixed4 x);

> ## Parameters

> x
>   Vector or scalar to determine its sign.

> ## Description

> Returns positive one, zero, or negative one for each of the components of x based on the component's sign.

>   1) Returns -1 component if the respective component of x is negative.
>   2) Returns 0 component if the respective component of x is zero.
>   3) Returns 1 component if the respective component of x is positive.
>   4) Ideally, NaN returns NaN.

> ## Reference Implementation

> sign for float3 could be implemented like this.

>     float3 sign(float x)
>     {
>       float3 val = a > 0;
>       return val - (a < 0);
>     }

> ## Profile Support

> sign is supported in all profiles except fp20.

> sign is very efficient in the gp4vp, gp4gp, gp4fp, vp40, and vp30 profiles that support the native SSG instruction.

> ## See Also

> max, min, saturate, step