OpenCL™ C 6.15.4. 常用函数

6.15.4. Common Functions
6.15.4. 常用函数

The following table describes the list of built-in common functions. These all operate component-wise. The description is per-component.

​下表描述了内置常用函数的列表。这些都是按分量操作的。描述是针对每个分量的。

The generic type name gentype indicates that the function can take any of

泛型类型名称gentype表示该函数可以采用以下任何类型

  • floatfloat2float3float4float8, or float16

  • double [39], double2double3double4double8 or double16

  • half [48], half2half3half4half8 or half16

as the type for the arguments.

作为参数的类型。

The generic type name gentypef indicates that the function can take any of

泛型类型名称gentypef表示该函数可以接受以下任何类型

  • floatfloat2float3float4float8, or float16

as the type for the arguments.

作为参数的类型。

The generic type name gentyped [49] indicates that the function can take any of

​泛型类型名称gentyped[49]表示该函数可以采用以下任何一种

  • doubledouble2double3double4double8 or double16

as the type for the arguments.

作为参数的类型。

The generic type name gentypeh [50] indicates that the function can take any of

​泛型类型名称gentypeh[50]表示该函数可以采用以下任何一种

  • halfhalf2half3half4half8 or half16

as the type for the arguments.

作为参数的类型。

All functions taking or returning half types are supported only when the cl_khr_fp16 extension macro is supported.

仅当支持cl_khr_fp16扩展宏时,才支持所有接受或返回half类型的函数。

Table 16. Built-in Scalar and Vector Argument Common Functions

表16 内置标量和矢量参数通用函数

Function

函数

Description

描述

gentype clamp(gentype x, gentype minval, gentype maxval)
gentypef clamp(gentypef x, float minval, float maxval)
gentyped clamp(gentyped x, double minval, double maxval)

gentypeh clamp(gentypeh x, half minval, half maxval)

Returns fmin(fmax(xminval), maxval). Results are undefined if minval > maxval.

返回fmin(fmax(x,minval),maxval)。如果minval>maxval,则结果未定义。

gentype degrees(gentype radians)

Converts radians to degrees, i.e. (180 / π) * radians.

将弧度转换为角度数,即(180/π)*弧度。

gentype max(gentype x, gentype y)
gentypef max(gentypef x, float y)
gentyped max(gentyped x, double y)

gentypeh max(gentypeh x, half y)

Returns y if x < y, otherwise it returns x. If x or y are infinite or NaN, the return values are undefined.

如果x<y,则返回y,否则返回x。如果x或y为无穷大或NaN,则返回值未定义。

gentype min(gentype x, gentype y)
gentypef min(gentypef x, float y)
gentyped min(gentyped x, double y)

gentypeh min(gentypeh x, half y)

Returns y if y < x, otherwise it returns x. If x or y are infinite or NaN, the return values are undefined.

如果y<x,则返回y,否则返回x。如果x或y为无穷大或NaN,则返回值未定义。

gentype mix(gentype x, gentype y, gentype a)
gentypef mix(gentypef x, gentypef y, float a)
gentyped mix(gentyped x, gentyped y, double a)

gentypeh mix(gentypeh x, gentypeh y, half a)

Returns the linear blend of x and y implemented as:

返回x和y的线性混合,实现为:

_x_ + (_y_ - _x_) * _a_
_a_ must be a value in the range [0.0, 1.0].
If _a_ is not in the range [0.0, 1.0], the return values are undefined.

_a_必须是[0.0,1.0]范围内的值。
如果_a_不在[0.0,1.0]范围内,则返回值未定义。

The half-precision mix function can be implemented using contractions such as mad or fma.

半精度混合函数可以使用mad或fma等缩写来实现。

gentype radians(gentype degrees)

Converts degrees to radians, i.e. (π / 180) * degrees.

将角度数转换为弧度,即(π/180)*度。

gentype step(gentype edge, gentype x)
gentypef step(float edge, gentypef x)
gentyped step(double edge, gentyped x)

gentypeh step(half edge, gentypeh x)

Returns 0.0 if x < edge, otherwise it returns 1.0.

如果x<edge,则返回0.0,否则返回1.0。

gentype smoothstep(gentype edge0, gentype edge1, gentype x)
gentypef smoothstep(float edge0, float edge1, gentypef x)
gentyped smoothstep(double edge0, double edge1, gentyped x)

gentypeh smoothstep(half edge0, half edge1, gentypeh x)

Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. This is useful in cases where you would want a threshold function with a smooth transition.

如果x<=edge0,则返回0.0;如果x>=edge1,则返回1.0;当edge0<x<edge1时,在0和1之间执行平滑的Hermite插值。这在需要平滑过渡的阈值函数的情况下非常有用。

This is equivalent to:

这相当于:

gentype t;
t = clamp ((x - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);

Results are undefined if edge0 >= edge1 or if xedge0 or edge1 is a NaN.

如果edge0>=edge1,或者x、edge0或edge1是NaN,则结果未定义。

The half-precision mix function can be implemented using contractions such as mad or fma.

半精度混合函数可以使用mad或fma等缩写来实现。

gentype sign(gentype x)

Returns 1.0 if x > 0, -0.0 if x = -0.0, +0.0 if x = +0.0, or -1.0 if x < 0. Returns 0.0 if x is a NaN.

如果x>0,返回1.0;如果x=-0.0,返回-0.0;如果x=+0.0,返回+0.0;如果x<0,返回-1.0。如果x是NaN,则返回0.0。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值