The following table describes the list of built-in geometric functions. These all operate component-wise. The description is per-component. floatn is float, float2, float3, or float4 and doublen is double, double2, double3, or double4. The built-in geometric functions are implemented using the round to nearest even rounding mode.

Table 1. Scalar and Vector Argument Built-in Geometric Function Table



float4 cross(float4 p0, float4 p1)
float3 cross(float3 p0, float3 p1)
double4 cross(double4 p0, double4 p1)
double3 cross(double3 p0, double3 p1)

Returns the cross product of and The w component of float4 result returned will be 0.0.

float dot(floatn p0, floatn p1)
double dot(doublen p0, doublen p1)

Compute dot product.

float distance(floatn p0, floatn p1)
double distance(doublen p0, doublen p1)

Returns the distance between p0 and p1. This is calculated as length(p0 - p1).

float length(floatn p)
double length(doublen p)

Return the length of vector p, i.e., √ p.x2 + p.y 2 + …​

floatn normalize(floatn p)
doublen normalize(doublen p)

Returns a vector in the same direction as p but with a length of 1.

float fast_distance(floatn p0, floatn p1)

Returns fast_length(p0 - p1).

float fast_length(floatn p)

Returns the length of vector p computed as:

half_sqrt(p.x2 + p.y2 + …​)

floatn fast_normalize(floatn p)

Returns a vector in the same direction as p but with a length of 1. fast_normalize is computed as:

+ p * half_rsqrt(p.x2 + p.y2 + …​)

+ The result shall be within 8192 ulps error from the infinitely precise result of


if (all(p == 0.0f))
    result = p;
    result = p / sqrt(p.x^2 + p.y^2 + ...);

+ with the following exceptions:

+ . If the sum of squares is greater than FLT_MAX then the value of the floating-point values in the result vector are undefined. . If the sum of squares is less than FLT_MIN then the implementation may return back p. . If the device is in “denorms are flushed to zero” mode, individual operand elements with magnitude less than sqrt(FLT_MIN) may be flushed to zero before proceeding with the calculation.

See Also

Document Notes

For more information, see the OpenCL C Specification

This page is extracted from the OpenCL C Specification. Fixes and changes should be made to the Specification, not directly.

Copyright (c) 2014-2020 Khronos Group. This work is licensed under a Creative Commons Attribution 4.0 International License.