Cg 3.1 Toolkit Documentation Cg / Standard Library / dot

## Name

dot - returns the scalar dot product of two vectors

## Synopsis

```float  dot(float  a, float  b);
float  dot(float1 a, float1 b);
float  dot(float2 a, float2 b);
float  dot(float3 a, float3 b);
float  dot(float4 a, float4 b);

half   dot(half  a, half  b);
half   dot(half1 a, half1 b);
half   dot(half2 a, half2 b);
half   dot(half3 a, half3 b);
half   dot(half4 a, half4 b);

fixed  dot(fixed  a, fixed  b);
fixed  dot(fixed1 a, fixed1 b);
fixed  dot(fixed2 a, fixed2 b);
fixed  dot(fixed3 a, fixed3 b);
fixed  dot(fixed4 a, fixed4 b);
```

a
First vector.
b
Second vector.

## Description

Returns the scalar dot product of two same-typed vectors a and b.

## Reference Implementation

dot for float4 vectors could be implemented this way:

```float dot(float4 a, float4 b)
{
return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w;
}
```

## Profile Support

dot is supported in all profiles.

The fixed3 dot product is very efficient in the fp20 and fp30 profiles.

The float3 and float4 dot products are very efficient in the vp20, vp30, vp40, arbvp1, fp30, fp40, and arbfp1 profiles.

The float2 dot product is very efficient in the fp40 profile. In optimal circumstances, two two-component dot products can sometimes be performed at the four-component and three-component dot product rate.