OpenCL C 7.OpenCL数值标准

7. OpenCL Numerical Compliance

7.OpenCL数值标准

This section describes features of the C99 and IEEE 754 standards that must be supported by all OpenCL compliant devices.

​本节描述了所有符合OpenCL的设备必须支持的C99和IEEE 754标准的功能。

This section describes the functionality that must be supported by all OpenCL devices for single precision floating-point numbers. Currently, only single precision floating-point is a requirement. Double-precision floating-point is an optional feature.

本节介绍所有OpenCL设备必须支持的单精度浮点数功能。目前,只需要单精度浮点运算。双精度浮点是一个可选功能。

7.1. Rounding Modes

7.1. 舍入模式

Floating-point calculations may be carried out internally with extra precision and then rounded to fit into the destination type. IEEE 754 defines four possible rounding modes:

浮点计算可以在内部进行,具有额外的精度,然后四舍五入以适应目标类型。IEEE 754定义了四种可能的舍入模式:

  • Round to nearest even

  • 四舍五入到最近的偶数

  • Round toward +∞

  • 向+∞方向舍入

  • Round toward -∞

  • 向-∞方向舍入

  • Round toward zero

  • 向零取整

Round to nearest even is currently the only rounding mode required by the OpenCL specification for single precision and double-precision operations and is therefore the default rounding mode [112]. In addition, only static selection of rounding mode is supported. Dynamically reconfiguring the rounding modes as specified by the IEEE 754 spec is unsupported.

​舍入到最接近的偶数是OpenCL规范目前要求的单精度和双精度操作的唯一舍入模式,因此是默认的舍入模式[112]。此外,仅支持静态选择舍入模式。不支持按照IEEE 754规范的规定动态重新配置舍入模式。

If the cl_khr_fp16 extension macro is supported, then if CL_FP_ROUND_TO_NEAREST is supported, the default rounding mode for half-precision floating-point operations will be round to nearest even; otherwise the default rounding mode will be round to zero.

如果支持cl_khr_fp16扩展宏,那么如果支持CL_FP_ROUND_TO_NEAREST ,则半精度浮点运算的默认舍入模式将四舍五入到最接近的偶数;否则,默认的舍入模式将四舍五入为零。

Conversions to half floating-point format must be correctly rounded using the indicated convert operator rounding mode or the default rounding mode for half-precision floating-point operations if no rounding mode is specified by the operator, or a C-style cast is used.

如果运算符没有指定舍入模式,或者使用了C风格转换,则必须使用指示的convert运算符舍入模式或半精度浮点操作的默认舍入模式来正确舍入转换为半浮点格式。

Conversions from half to integer format shall correctly round using the indicated convert operator rounding mode, or towards zero if no rounding mode is specified by the operator or a C-style cast is used. All conversions from half to floating-point formats are exact.

从half值到整数格式的转换应使用指定的convert运算符舍入模式正确舍入,或者如果运算符没有指定舍入模式或使用C风格转换,则应向零舍入。从half值格式到浮点格式的所有转换都是精确的。

If the cl_khr_select_fprounding_mode extension macro is supported, the floating-point rounding mode may be specified using the following #pragma in the OpenCL program source:

如果支持cl_khr_select_fprounding_mode扩展宏,则可以在OpenCL程序源代码中使用以下#pragma指定浮点舍入模式:

#pragma OPENCL SELECT_ROUNDING_MODE <rounding-mode>

The <rounding-mode> may be one of the following values:

<舍入模式>可以是以下值之一:

  • rte - round to nearest even

  • rte-舍入到最近的偶数

  • rtz - round to zero

  • rtz-舍入到归零

  • rtp - round to positive infinity

  • rtp-舍入到正无穷大

  • rtn - round to negative infinity

  • rtn-舍入到负无穷大

If this extensions is supported then the OpenCL implementation must support all four rounding modes for single precision floating-point.

如果支持此扩展,则OpenCL实现必须支持单精度浮点的所有四种舍入模式。

The #pragma sets the rounding mode for all instructions that operate on floating-point types (scalar or vector types) or produce floating-point values that follow this pragma in the program source until the next #pragma. Note that the rounding mode specified for a block of code is known at compile time. When inside a compound statement, the pragma takes effect from its occurrence until another #pragma is encountered (including within a nested compound statement), or until the end of the compound statement; at the end of a compound statement the state for the pragma is restored to its condition just before the compound statement. Except where otherwise documented, the callee functions do not inherit the rounding mode of the caller function.

#pragma为所有对浮点类型(标量或矢量类型)进行操作或在程序源代码中生成遵循此pragma的浮点值的指令设置舍入模式,直到下一个#pragma。请注意,为代码块指定的舍入模式在编译时是已知的。当在复合语句中时,#pragma从出现开始生效,直到遇到另一个#pragma(包括在嵌套的复合语句中),或者直到复合语句结束;在复合语句的末尾,#pragma的状态恢复到复合语句之前的状态。除非另有说明,否则被调用者函数不会继承调用者函数的舍入模式。

If the cl_khr_select_fprounding_mode extension is enabled, the __ROUNDING_MODE__ preprocessor symbol shall be defined to be one of the following according to the current rounding mode:

如果启用了cl_khr_select_fprounding_mode扩展,则应根据当前舍入模式将__ROUNDING_MODE__ 预处理器符号定义为以下之一:

#define __ROUNDING_MODE__ rte
#define __ROUNDING_MODE__ rtz
#define __ROUNDING_MODE__ rtp
#define __ROUNDING_MODE__ rtz

This is intended to enable remapping foo() to foo_rte() by the preprocessor by using:

这是为了使预处理器能够通过使用以下命令将foo()重新映射到foo_rte():

#define foo foo ## __ROUNDING_MODE__

The default rounding mode is round to nearest even. The Math FunctionsCommon Functions, and Geometric Functions are implemented with the round to nearest even rounding mode. Various built-in conversions and the vstore_half and vstorea_half built-in functions that do not specify a rounding mode inherit the current rounding mode. Conversions from floating-point to integer type always use rtz mode, except where the user specifically asks for another rounding mode.

​默认的舍入模式是四舍五入到最接近的偶数。数学函数、通用函数和几何函数都是通过四舍五入模式实现的。各种内置转换以及未指定舍入模式的vstore_half和vstorea_half内置函数继承了当前的舍入模式。从浮点到整数类型的转换始终使用rtz模式,除非用户特别要求另一种舍入模式

 

The cl_khr_select_fprounding_mode extension was deprecated in OpenCL 1.1, and its use is not recommended.

 

cl_khr_select_fprounding_mode扩展在OpenCL 1.1中已被弃用,不建议使用。

7.2. INF, NaN and Denormalized Numbers

7.2. INF、NaN和非规范化数

INF and NaNs must be supported. Support for signaling NaNs is not required.

必须支持INF和NaN。不需要对NaN信号的支持。

Support for denormalized numbers with single precision floating-point is optional. Denormalized single precision floating-point numbers passed as input or produced as the output of single precision floating-point operations such as add, sub, mul, divide, and the functions defined in math functionscommon functions, and geometric functions may be flushed to zero.

​支持具有单精度浮点的非规范化数字是可选的。作为输入传递或作为单精度浮点运算(如加、减、乘、除)输出产生的非规范化单精度浮点数,以及数学函数、通用函数和几何函数中定义的函数,可能会被清零。

7.3. Floating-Point Exceptions

7.3. 浮点异常

Floating-point exceptions are disabled in OpenCL. The result of a floating-point exception must match the IEEE 754 spec for the exceptions not enabled case. Whether and when the implementation sets floating-point flags or raises floating-point exceptions is implementation-defined. This standard provides no method for querying, clearing or setting floating-point flags or trapping raised exceptions. Due to non-performance, non-portability of trap mechanisms and the impracticality of servicing precise exceptions in a vector context (especially on heterogeneous hardware), such features are discouraged.

OpenCL中禁用浮点异常。浮点异常的结果必须与IEEE 754规范中未启用异常的情况相匹配。实现是否以及何时设置浮点标志或引发浮点异常是由实现定义的。本标准没有提供查询、清除或设置浮点标志或捕获引发的异常的方法。由于陷阱机制的非性能、不可移植性以及在向量上下文中(特别是在异构硬件上)服务精确异常的不切实际性,这些功能是不受欢迎的。

Implementations that nevertheless support such operations through an extension to the standard shall initialize with all exception flags cleared and the exception masks set so that exceptions raised by arithmetic operations do not trigger a trap to be taken. If the underlying work is reused by the implementation, the implementation is however not responsible for reclearing the flags or resetting exception masks to default values before entering the kernel. That is to say that kernels that do not inspect flags or enable traps are licensed to expect that their arithmetic will not trigger a trap. Those kernels that do examine flags or enable traps are responsible for clearing flag state and disabling all traps before returning control to the implementation. Whether or when the underlying work-item (and accompanying global floating-point state if any) is reused is implementation-defined.

尽管如此,通过标准扩展支持此类操作的实现应初始化,清除所有异常标志并设置异常掩码,以便算术运算引发的异常不会触发陷阱。但是,如果底层工作被实现重用,则实现不负责在进入内核之前重新提取标志或将异常掩码重置为默认值。也就是说,不检查标志或启用陷阱的内核被授权期望其算法不会触发陷阱。那些检查标志或启用陷阱的内核负责在将控制权返回给实现之前清除标志状态并禁用所有陷阱。是否或何时重用底层工作项(以及附带的全局浮点状态,如果有的话)是由实现定义的。

The expressions math_errorhandling and MATH_ERREXCEPT are reserved for use by this standard, but not defined. Implementations that extend this specification with support for floating-point exceptions shall define math_errorhandling and MATH_ERREXCEPT per TC2 to the C99 Specification.

​表达式math_errorhandling和MATH_ERREXCEPT 保留供本标准使用,但未定义。扩展此规范并支持浮点异常的实现应根据C99规范的TC2定义math_errorhandling和math_ERREXCEPT。

7.4. Relative Error as ULPs

7.4. ULP的相对错误

In this section we discuss the maximum relative error defined as ulp (units in the last place). Addition, subtraction, multiplication, fused multiply-add and conversion between integer and a single precision floating-point format are IEEE 754 compliant and are therefore correctly rounded. Conversion between floating-point formats and explicit conversions must be correctly rounded.

​在本节中,我们将讨论定义为ulp(最后一个单位)的最大相对错误。加法、减法、乘法、融合乘法加法和整数与单精度浮点格式之间的转换符合IEEE 754标准,因此被正确四舍五入。浮点格式和显式转换之间的转换必须正确四舍五入。

If the cl_khr_fp16 extension macro is supported, addition, subtraction, multiplication, fused multiply-add operations on half types are required to be correctly rounded using the default rounding mode for half-precision floating-point operations.

如果支持cl_khr_fp16扩展宏,则需要使用半精度浮点运算的默认舍入模式对half类型的加法、减法、乘法、融合乘加运算进行正确舍入。

The ULP is defined as follows:

ULP定义如下:

If x is a real number that lies between two finite consecutive floating-point numbers a and b, without being equal to one of them, then ulp(x) = |b - a|, otherwise ulp(x) is the distance between the two non-equal finite floating-point numbers nearest x. Moreover, ulp(NaN) is NaN.

如果x是介于两个有限连续浮点数a和b之间的实数,且不等于其中之一,则ulp(x)=|b-a|,否则ulp(x)是最接近x的两个不相等的有限浮点数之间的距离。此外,ulp(NaN)是NaN。

Attribution: This definition was taken with consent from Jean-Michel Muller with slight clarification for behavior at zero.

归因:这一定义是在让-米歇尔·穆勒的同意下得出的,对零行为进行了轻微的澄清。

Jean-Michel Muller. On the definition of ulp(x). RR-5504, INRIA. 2005, pp.16. <inria-00070503> Currently hosted at https://hal.inria.fr/inria-00070503/document.

​让-米歇尔·穆勒。关于ulp(x)的定义。RR-5504,印度自然资源研究所,2005年,第16页<inria-00070503>目前托管于https://hal.inria.fr/inria-00070503/document.

The following table describes the minimum accuracy of single precision floating-point arithmetic operations given as ULP values. The reference value used to compute the ULP value of an arithmetic operation is the infinitely precise result. 0 ulp is used for math functions that do not require rounding.

下表描述了作为ULP值给出的单精度浮点算术运算的最小精度。用于计算算术运算的ULP值的参考值是无限精确的结果。0ulp用于不需要舍入的数学函数。

Result overflow within the specified ULP error is permitted. Math functions are allowed to return infinity for a finite reference value when the next floating-point number that would be representable after the finite maximum, if there was sufficient range, meets ULP error tolerance.

允许在指定的ULP错误范围内发生结果溢出。当在有限最大值之后可表示的下一个浮点数(如果有足够的范围)满足ULP误差容限时,允许数学函数返回有限参考值的无穷大。

Table 65. ULP Values for Single-Precision Built-in Math Functions

表65 单精度内置数学函数的ULP值

Function

函数

Min Accuracy - ULP values

最小精度-ULP值

x + y

Correctly rounded

x - y

Correctly rounded

x * y

Correctly rounded

1.0 / x

≤ 2.5 ulp

x / y

≤ 2.5 ulp

  

acos

≤ 4 ulp

acospi

≤ 5 ulp

asin

≤ 4 ulp

asinpi

≤ 5 ulp

atan

≤ 5 ulp

atan2

≤ 6 ulp

atanpi

≤ 5 ulp

atan2pi

≤ 6 ulp

acosh

≤ 4 ulp

asinh

≤ 4 ulp

atanh

≤ 5 ulp

cbrt

≤ 2 ulp

ceil

Correctly rounded

clamp

0 ulp

copysign

0 ulp

cos

≤ 4 ulp

cosh

≤ 4 ulp

cospi

≤ 4 ulp

cross

absolute error tolerance of 'max * max * (3 * FLT_EPSILON)' per vector component, where max is the maximum input operand magnitude

 

每个矢量分量的“max*max*(3*FLT_EPSILON)”的绝对误差容限,其中max是最大输入操作数幅度

degrees

≤ 2 ulp

distance

≤ 2.5 + 2n ulp, for gentype with vector width n

dot

absolute error tolerance of 'max * max * (2n - 1) * FLT_EPSILON', for vector width n and maximum input operand magnitude max across all vector components

 

对于所有矢量分量的向量宽度n和最大输入操作数幅度max,'max*max*(2n-1)*FLT_EPSILON'的绝对误差容限

erfc

≤ 16 ulp

erf

≤ 16 ulp

exp

≤ 3 ulp

exp2

≤ 3 ulp

exp10

≤ 3 ulp

expm1

≤ 3 ulp

fabs

0 ulp

fdim

Correctly rounded

floor

Correctly rounded

fma

Correctly rounded

fmax

0 ulp

fmin

0 ulp

fmod

0 ulp

fract

Correctly rounded

frexp

0 ulp

hypot

≤ 4 ulp

ilogb

0 ulp

length

≤ 2.75 + 0.5n ulp, for gentype with vector width n

ldexp

Correctly rounded

lgamma

Undefined

lgamma_r

Undefined

log

≤ 3 ulp

log2

≤ 3 ulp

log10

≤ 3 ulp

log1p

≤ 2 ulp

logb

0 ulp

mad

Implemented either as a correctly rounded fma or as a multiply followed by an add both of which are correctly rounded

 

实现为正确四舍五入的fma或乘后加,两者都正确四舍五入

max

0 ulp

maxmag

0 ulp

min

0 ulp

minmag

0 ulp

mix

absolute error tolerance of 1e-3

modf

0 ulp

nan

0 ulp

nextafter

0 ulp

normalize

≤ 2 + n ulp, for gentype with vector width n

pow(xy)

≤ 16 ulp

pown(xy)

≤ 16 ulp

powr(xy)

≤ 16 ulp

radians

≤ 2 ulp

remainder

0 ulp

remquo

0 ulp

rint

Correctly rounded

rootn

≤ 16 ulp

round

Correctly rounded

rsqrt

≤ 2 ulp

sign

0 ulp

sin

≤ 4 ulp

sincos

≤ 4 ulp for sine and cosine values

sinh

≤ 4 ulp

sinpi

≤ 4 ulp

smoothstep

absolute error tolerance of 1e-5

sqrt

≤ 3 ulp

step

0 ulp

tan

≤ 5 ulp

tanh

≤ 5 ulp

tanpi

≤ 6 ulp

tgamma

≤ 16 ulp

trunc

Correctly rounded

  

half_cos

≤ 8192 ulp

half_divide

≤ 8192 ulp

half_exp

≤ 8192 ulp

half_exp2

≤ 8192 ulp

half_exp10

≤ 8192 ulp

half_log

≤ 8192 ulp

half_log2

≤ 8192 ulp

half_log10

≤ 8192 ulp

half_powr

≤ 8192 ulp

half_recip

≤ 8192 ulp

half_rsqrt

≤ 8192 ulp

half_sin

≤ 8192 ulp

half_sqrt

≤ 8192 ulp

half_tan

≤ 8192 ulp

  

fast_distance

≤ 8191.5 + 2n ulp, for gentype with vector width n

fast_length

≤ 8191.5 + n ulp, for gentype with vector width n

fast_normalize

≤ 8192 + n ulp, for gentype with vector width n

  

native_cos

Implementation-defined

native_divide

Implementation-defined

native_exp

Implementation-defined

native_exp2

Implementation-defined

native_exp10

Implementation-defined

native_log

Implementation-defined

native_log2

Implementation-defined

native_log10

Implementation-defined

native_powr

Implementation-defined

native_recip

Implementation-defined

native_rsqrt

Implementation-defined

native_sin

Implementation-defined

native_sqrt

Implementation-defined

native_tan

Implementation-defined

The following table describes the minimum accuracy of single precision floating-point arithmetic operations given as ULP values for the embedded profile. The reference value used to compute the ULP value of an arithmetic operation is the infinitely precise result. 0 ulp is used for math functions that do not require rounding.

下表描述了作为嵌入式配置文件的ULP值给出的单精度浮点算术运算的最小精度。用于计算算术运算的ULP值的参考值是无限精确的结果。0ulp用于不需要舍入的数学函数。

Table 66. ULP Values for the Embedded Profile

表66 嵌入式配置文件的ULP值

Function

函数

Min Accuracy - ULP values

最小精度-ULP值

x + y

Correctly rounded

x - y

Correctly rounded

x * y

Correctly rounded

1.0 / x

≤ 3 ulp

x / y

≤ 3 ulp

  

acos

≤ 4 ulp

acospi

≤ 5 ulp

asin

≤ 4 ulp

asinpi

≤ 5 ulp

atan

≤ 5 ulp

atan2

≤ 6 ulp

atanpi

≤ 5 ulp

atan2pi

≤ 6 ulp

acosh

≤ 4 ulp

asinh

≤ 4 ulp

atanh

≤ 5 ulp

cbrt

≤ 4 ulp

ceil

Correctly rounded

clamp

0 ulp

copysign

0 ulp

cos

≤ 4 ulp

cosh

≤ 4 ulp

cospi

≤ 4 ulp

cross

Implementation-defined

degrees

≤ 2 ulp

distance

Implementation-defined

dot

Implementation-defined

erfc

≤ 16 ulp

erf

≤ 16 ulp

exp

≤ 4 ulp

exp2

≤ 4 ulp

exp10

≤ 4 ulp

expm1

≤ 4 ulp

fabs

0 ulp

fdim

Correctly rounded

floor

Correctly rounded

fma

Correctly rounded

fmax

0 ulp

fmin

0 ulp

fmod

0 ulp

fract

Correctly rounded

frexp

0 ulp

hypot

≤ 4 ulp

ilogb

0 ulp

ldexp

Correctly rounded

length

Implementation-defined

log

≤ 4 ulp

log2

≤ 4 ulp

log10

≤ 4 ulp

log1p

≤ 4 ulp

logb

0 ulp

mad

Any value allowed (infinite ulp)

max

0 ulp

maxmag

0 ulp

min

0 ulp

minmag

0 ulp

mix

Implementation-defined

modf

0 ulp

nan

0 ulp

normalize

Implementation-defined

nextafter

0 ulp

pow(xy)

≤ 16 ulp

pown(xy)

≤ 16 ulp

powr(xy)

≤ 16 ulp

radians

≤ 2 ulp

remainder

0 ulp

remquo

0 ulp

rint

Correctly rounded

rootn

≤ 16 ulp

round

Correctly rounded

rsqrt

≤ 4 ulp

sign

0 ulp

sin

≤ 4 ulp

sincos

≤ 4 ulp for sine and cosine values

sinh

≤ 4 ulp

sinpi

≤ 4 ulp

smoothstep

Implementation-defined

sqrt

≤ 4 ulp

step

0 ulp

tan

≤ 5 ulp

tanh

≤ 5 ulp

tanpi

≤ 6 ulp

tgamma

≤ 16 ulp

trunc

Correctly rounded

  

half_cos

≤ 8192 ulp

half_divide

≤ 8192 ulp

half_exp

≤ 8192 ulp

half_exp2

≤ 8192 ulp

half_exp10

≤ 8192 ulp

half_log

≤ 8192 ulp

half_log2

≤ 8192 ulp

half_log10

≤ 8192 ulp

half_powr

≤ 8192 ulp

half_recip

≤ 8192 ulp

half_rsqrt

≤ 8192 ulp

half_sin

≤ 8192 ulp

half_sqrt

≤ 8192 ulp

half_tan

≤ 8192 ulp

  

fast_distance

Implementation-defined

fast_length

Implementation-defined

fast_normalize

Implementation-defined

  

native_cos

Implementation-defined

native_divide

Implementation-defined

native_exp

Implementation-defined

native_exp2

Implementation-defined

native_exp10

Implementation-defined

native_log

Implementation-defined

native_log2

Implementation-defined

native_log10

Implementation-defined

native_powr

Implementation-defined

native_recip

Implementation-defined

native_rsqrt

Implementation-defined

native_sin

Implementation-defined

native_sqrt

Implementation-defined

native_tan

Implementation-defined

The following table describes the minimum accuracy of commonly used single precision floating-point arithmetic operations given as ULP values if the -cl-unsafe-math-optimizations compiler option is specified when compiling or building an OpenCL program. For derived implementations, the operations used in the derivation may themselves be relaxed according to the following table. The minimum accuracy of math functions not defined in the following table when the -cl-unsafe-math-optimizations compiler option is specified is as defined in ULP values for single precision built-in math functions when operating in the full profile, and as defined in ULP values for the embedded profile when operating in the embedded profile. The reference value used to compute the ULP value of an arithmetic operation is the infinitely precise result. 0 ulp is used for math functions that do not require rounding.

​下表描述了如果在编译或构建OpenCL程序时指定了-cl-unsafe-math-optimizations编译器选项,则作为ULP值给出的常用单精度浮点算术运算的最小精度。对于派生实现,派生中使用的操作本身可以根据下表放宽。当指定-cl-unsafe-math-optimizations编译器选项时,下表中未定义的数学函数的最小精度与在完整配置文件中操作时单精度内置数学函数的ULP值中定义的精度相同,与在嵌入式配置文件中运行时嵌入式配置文件的ULP数值中定义的精确度相同。用于计算算术运算的ULP值的参考值是无限精确的结果。0ulp用于不需要舍入的数学函数。

Defined minimum accuracy of single precision floating-point arithmetic operations and builtins with -cl-unsafe-math-optimizations requires support for OpenCL C 2.0 or newer.

​定义的单精度浮点算术运算的最小精度和内置的--cl-unsafe-math-optimizations需要支持OpenCL C 2.0或更高版本。

Table 67. ULP Values for Single-Precision Built-in Math Functions With Unsafe Math Optimizations in the Full and Embedded Profiles

表67 全配置文件和嵌入式配置文件中具有不安全数学优化的单精度内置数学函数的ULP值

Function

函数

Minimum Accuracy

最低精度

1.0 / x

≤ 2.5 ulp for x in the domain of 2-126 to 2126 for the full profile, and ≤ 3 ulp for the embedded profile.

 

对于全轮廓,2-126至2126范围内的x≤2.5 ulp,对于嵌入式轮廓,≤3 ulp。

x / y

≤ 2.5 ulp for x in the domain of 2-62 to 262 and y in the domain of 2-62 to 262 for the full profile, and ≤ 3 ulp for the embedded profile.

 

对于全轮廓,x在2-62至262的域中≤2.5ulp,y在2-62到262的域内≤3ulp。

acos(x)

≤ 4096 ulp

acosh(x)

Derived implementations may implement as log(x + sqrt(x * x - 1)). For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为log(x+sqrt(x*x-1))。对于非派生实现,误差≤8192 ulp。

acospi(x)

Derived implementations may implement as acos(x) * M_PI_F. For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为acos(x)*M_PI_F。对于非派生实现,误差≤8192 ulp。

asin(x)

≤ 4096 ulp

asinh(x)

Derived implementations may implement as log(x + sqrt(x * x + 1)). For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为log(x+sqrt(x*x+1))。对于非派生实现,误差≤8192 ulp。

asinpi(x)

Derived implementations may implement as asin(x) * M_PI_F. For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为asin(x)*M_PI_F。对于非派生实现,误差≤8192 ulp。

atan(x)

≤ 4096 ulp

atanh(x)

Defined for x in the domain (-1, 1). For x in [-2-10, 2-10], derived implementations may implement as x. For x outside of [-2-10, 2-10], derived implementations may implement as 0.5f * log((1.0f + x) / (1.0f - x)). For non-derived implementations, the error is ≤ 8192 ulp.

 

在域(-1,1)中为x定义。对于[-2-10,2-10]中的x,派生实现可以实现为x。对于[-2-10,2-10]之外的x,派生实现可以实现为0.5f*log((1.0f+x)/(1.0f-x))。对于非派生实现,误差≤8192 ulp。

atanpi(x)

Derived implementations may implement as atan(x) * M_1_PI_F. For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为atan(x)*M_1_PI_F。对于非派生实现,错误≤8192 ulp。

atan2(yx)

Derived implementations may implement as atan(y / x) for x > 0, atan(y / x) + M_PI_F for x < 0 and y > 0, and atan(y / x) - M_PI_F for x < 0 and y < 0. For non-derived implementations, the error is ≤ 8192 ulp.

 

对于x>0,派生实现可以实现为atan(y/x),对于x<0和y>0,可以实现为aan(y/x)+M_PI_F,对于x=0和y<0,可以实现成atan(y/x)-M_PI_F。对于非派生实现,误差≤8192 ulp。

atan2pi(yx)

Derived implementations may implement as atan2(yx) * M_1_PI_F. For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为atan2(y,x)*M_1_PI_F。对于非派生实现,误差≤8192 ulp。

cbrt(x)

Derived implementations may implement as rootn(x, 3). For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为rootn(x,3)。对于非派生实现,误差≤8192 ulp。

cos(x)

For x in the domain [-π, π], the maximum absolute error is ≤ 2-11 and larger otherwise.

 

对于[-π,π]域中的x,最大绝对误差≤2-11,否则更大。

cosh(x)

Defined for x in the domain [-88, 88]. Derived implementations may implement as 0.5f * (exp(x) + exp(-x)). For non-derived implementations, the error is ≤ 8192 ulp.

 

在域[-88,88]中为x定义。派生实现可以实现为0.5f*(exp(x)+exp(-x))。对于非派生实现,误差≤8192 ulp。

cospi(x)

For x in the domain [-1, 1], the maximum absolute error is ≤ 2-11 and larger otherwise.

 

对于域[-1,1]中的x,最大绝对误差≤2-11,否则更大。

exp(x)

≤ 3 + floor(fabs(2 * x)) ulp for the full profile, and ≤ 4 ulp for the embedded profile.

 

全概述≤ 3 + floor(fabs(2 * x))ulp,嵌入式概述≤4ULP。

exp2(x)

≤ 3 + floor(fabs(2 * x)) ulp for the full profile, and ≤ 4 ulp for the embedded profile.

 

全概述≤ 3 + floor(fabs(2 * x))ulp,嵌入式概述≤4ULP。

exp10(x)

Derived implementations may implement as exp2(x * log2(10)). For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为exp2(x*log2(10))。对于非派生实现,误差≤8192 ulp。

expm1(x)

Derived implementations may implement as exp(x) - 1. For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为exp(x)-1。对于非派生实现,误差≤8192 ulp。

log(x)

For x in the domain [0.5, 2] the maximum absolute error is ≤ 2-21; otherwise the maximum error is ≤ 3 ulp for the full profile and ≤ 4 ulp for the embedded profile.

 

对于[0.5,2]域中的x,最大绝对误差≤2-21;否则,全轮廓的最大误差≤3ulp,嵌入式轮廓的最大偏差≤4ulp。

log2(x)

For x in the domain [0.5, 2] the maximum absolute error is ≤ 2-21; otherwise the maximum error is ≤ 3 ulp for the full profile and ≤ 4 ulp for the embedded profile.

 

对于[0.5,2]域中的x,最大绝对误差≤2-21;否则,全轮廓的最大误差≤3ulp,嵌入式轮廓的最大偏差≤4ulp。

log10(x)

For x in the domain [0.5, 2] the maximum absolute error is ≤ 2-21; otherwise the maximum error is ≤ 3 ulp for the full profile and ≤ 4 ulp for the embedded profile.

 

对于[0.5,2]域中的x,最大绝对误差≤2-21;否则,全轮廓的最大误差≤3ulp,嵌入式轮廓的最大偏差≤4ulp。

log1p(x)

Derived implementations may implement as log(x + 1). For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为log(x+1)。对于非派生实现,误差≤8192 ulp。

pow(xy)

Undefined for x = 0 and y = 0. Undefined for x < 0 and non-integer y. Undefined for x < 0 and y outside the domain [-224, 224]. For x > 0 or x < 0 and even y, derived implementations may implement as exp2(y * log2(fabs(x))). For x < 0 and odd y, derived implementations may implement as -exp2(y * log2(fabs(x)). For x == 0 and non-zero y, for derived implementations may return zero. For non-derived implementations, the error is ≤ 8192 ulp. [113]

 

​对于x=0和y=0,未定义。对于x<0和非整数y,未定义。对于域[-224224]外的x<0和y未定义。对于x>0或x<0甚至y,派生实现可以实现为exp2(y*log2(fabs(x)))。对于x<0和奇数y,派生实现可以实现为-exp2(y*log2(fabs(x))。对于x==0和非零y,对于派生实现可能返回零。对于非派生实现,误差≤8192 ulp。 [113]

pown(xy)

Defined only for integer values of y. Undefined for x = 0 and y = 0. For x >= 0 or x < 0 and even y, derived implementations may implement as exp2(y * log2(fabs(x))). For x < 0 and odd y, derived implementations may implement as -exp2(y * log2(fabs(x))). For non-derived implementations, the error is ≤ 8192 ulp.

 

仅对y的整数值定义。对于x=0和y=0,未定义。对于x>=0或x<0甚至y,派生实现可以实现为exp2(y*log2(fabs(x)))。对于x<0和奇数y,派生实现可以实现为-exp2(y*log2(fabs(x)))。对于非派生实现,误差≤8192 ulp。

powr(xy)

Defined only for x >= 0. Undefined for x = 0 and y = 0. Derived implementations may implement as exp2(y * log2(x)). For non-derived implementations, the error is ≤ 8192 ulp.

 

仅为x>=0定义。对于x=0和y=0,未定义。派生实现可以实现为exp2(y*log2(x))。对于非派生实现,误差≤8192 ulp。

rootn(xy)

Defined for x > 0 when y is non-zero, derived implementations may implement this case as exp2(log2(x) / y). Defined for x < 0 when y is odd, derived implementations may implement this case as -exp2(log2(-x) / y). Defined for x = +/-0 when y > 0, derived implementations may return +0 in this case. For non-derived implementations, the error is ≤ 8192 ulp.

 

当y为非零时,为x>0定义,派生实现可以将这种情况实现为exp2(log2(x)/y)。当y为奇数时,为x<0定义,派生实现可以将这种情况实现为-exp2(log2(-x)/y)。当y>0时,为x=+/-0定义,在这种情况下,派生实现可能会返回+0。对于非派生实现,误差≤8192 ulp。

sin(x)

For x in the domain [-π, π], the maximum absolute error is ≤ 2-11 and larger otherwise.

 

对于[-π,π]域中的x,最大绝对误差≤2-11,否则更大。

sincos(x)

ulp values as defined for sin(x) and cos(x).

 

如sin(x)和cos(x)所定义的ulp值。

sinh(x)

Defined for x in the domain [-88,88]. For x in [-2-10, 2-10], derived implementations may implement as x. For x outside of [-2-10, 2-10], derived implementations may implement as 0.5f * (exp(x) - exp(-x)). For non-derived implementations, the error is ≤ 8192 ulp.

 

在域[-88,88]中为x定义。对于[-2-10,2-10]中的x,派生实现可以实现为x。对于[-2-10,2-10]之外的x,派生实现可以实现为0.5f*(exp(x)-exp(-x))。对于非派生实现,误差≤8192 ulp。

sinpi(x)

For x in the domain [-1, 1], the maximum absolute error is ≤ 2-11 and larger otherwise.

 

对于域[-1,1]中的x,最大绝对误差≤2-11,否则更大。

tan(x)

Derived implementations may implement as sin(x) * (1.0f / cos(x)). For non-derived implementations, the error is ≤ 8192 ulp.

 

派生实现可以实现为sin(x)*(1.0f/cos(x))。对于非派生实现,误差≤8192 ulp。

tanh(x)

Defined for x in the domain [-∞, ∞]. For x in [-2-10, 2-10], derived implementations may implement as x. For x outside of [-2-10, 2-10], derived implementations may implement as (exp(x) - exp(-x)) / (exp(x) + exp(-x)). For non-derived implementations, the error is ≤ 8192 ULP.

 

在域[-∞,∞]中为x定义。对于[-2-10,2-10]中的x,派生实现可以实现为x。对于[-2-10,2-10]之外的x,派生实现可以实现为(exp(x)-exp(-x))/(exp。对于非派生实现,误差≤8192 ULP。

tanpi(x)

Derived implementations may implement as tan(x * M_PI_F). For non-derived implementations, the error is ≤ 8192 ulp for x in the domain [-1, 1].

 

派生实现可以实现为tan(x*M_PI_F)。对于非派生实现,域[-1,1]中x的误差≤8192 ulp。

x * y + z

Implemented either as a correctly rounded fma or as a multiply and an add both of which are correctly rounded.

 

实现为正确舍入的fma或乘法和加法,两者都正确舍入。

The following table describes the minimum accuracy of double-precision floating-point arithmetic operations given as ULP values. The reference value used to compute the ULP value of an arithmetic operation is the infinitely precise result. 0 ulp is used for math functions that do not require rounding.

下表描述了作为ULP值给出的双精度浮点算术运算的最小精度。用于计算算术运算的ULP值的参考值是无限精确的结果。0ulp用于不需要舍入的数学函数。

Table 68. ULP Values for Double-Precision Built-in Math Functions

表68 双精度内置数学函数的ULP值

Function

函数

Min Accuracy - ULP values

最小精度-ULP值

x + y

Correctly rounded

x - y

Correctly rounded

x * y

Correctly rounded

1.0 / x

Correctly rounded

x / y

Correctly rounded

  

acos

≤ 4 ulp

acospi

≤ 5 ulp

asin

≤ 4 ulp

asinpi

≤ 5 ulp

atan

≤ 5 ulp

atan2

≤ 6 ulp

atanpi

≤ 5 ulp

atan2pi

≤ 6 ulp

acosh

≤ 4 ulp

asinh

≤ 4 ulp

atanh

≤ 5 ulp

cbrt

≤ 2 ulp

ceil

Correctly rounded

clamp

0 ulp

copysign

0 ulp

cos

≤ 4 ulp

cosh

≤ 4 ulp

cospi

≤ 4 ulp

cross

absolute error tolerance of 'max * max * (3 * FLT_EPSILON)' per vector component, where max is the maximum input operand magnitude

 

每个矢量分量的“max*max*(3*FLT_EPSILON)”的绝对误差容限,其中max是最大输入操作数幅度

degrees

≤ 2 ulp

distance

≤ 5.5 + 2n ulp, for gentype with vector width n

 

≤5.5+2n ulp,对于矢量宽度为n的正型

dot

absolute error tolerance of 'max * max * (2n - 1) * FLT_EPSILON', for vector width n and maximum input operand magnitude max across all vector components

 

对于所有矢量分量的向量宽度n和最大输入操作数幅度max,'max*max*(2n-1)*FLT_EPSILON'的绝对误差容限

erfc

≤ 16 ulp

erf

≤ 16 ulp

exp

≤ 3 ulp

exp2

≤ 3 ulp

exp10

≤ 3 ulp

expm1

≤ 3 ulp

fabs

0 ulp

fdim

Correctly rounded

floor

Correctly rounded

fma

Correctly rounded

fmax

0 ulp

fmin

0 ulp

fmod

0 ulp

fract

Correctly rounded

frexp

0 ulp

hypot

≤ 4 ulp

ilogb

0 ulp

length

≤ 5.5 + n ulp, for gentype with vector width n

 

≤5.5+n ulp,适用于矢量宽度为n的gentype

ldexp

Correctly rounded

log

≤ 3 ulp

log2

≤ 3 ulp

log10

≤ 3 ulp

log1p

≤ 2 ulp

logb

0 ulp

mad

Any value allowed (infinite ulp)

max

0 ulp

maxmag

0 ulp

min

0 ulp

minmag

0 ulp

mix

Implementation-defined

modf

0 ulp

nan

0 ulp

nextafter

0 ulp

normalize

≤ 4.5 + n ulp, for gentype with vector width n

 

≤4.5+n ulp,适用于矢量宽度为n的gentype

pow(xy)

≤ 16 ulp

pown(xy)

≤ 16 ulp

powr(xy)

≤ 16 ulp

radians

≤ 2 ulp

remainder

0 ulp

remquo

0 ulp

rint

Correctly rounded

rootn

≤ 16 ulp

round

Correctly rounded

rsqrt

≤ 2 ulp

sign

0 ulp

sin

≤ 4 ulp

sincos

≤ 4 ulp for sine and cosine values

sinh

≤ 4 ulp

sinpi

≤ 4 ulp

smoothstep

Implementation-defined

step

0 ulp

fsqrt

Correctly rounded

tan

≤ 5 ulp

tanh

≤ 5 ulp

tanpi

≤ 6 ulp

tgamma

≤ 16 ulp

trunc

Correctly rounded

If the cl_khr_fp16 extension macro is supported, the following table describes the minimum accuracy of half-precision floating-point arithmetic operations given as ULP values. The reference value used to compute the ULP value of an arithmetic operation is the infinitely precise result. 0 ulp is used for math functions that do not require rounding.

如果支持cl_khr_fp16扩展宏,下表描述了作为ULP值给出的半精度浮点算术运算的最小精度。用于计算算术运算的ULP值的参考值是无限精确的结果。0ulp用于不需要舍入的数学函数。

Table 69. ULP Values for Half-Precision Floating-Point Arithmetic Operations

表69 half精度浮点算术运算的ULP值

Function

函数

Min Accuracy - Full Profile

最小精度-全轮廓

Min Accuracy - Embedded Profile

最小精度-嵌入式轮廓

x + y

Correctly rounded

Correctly rounded

x - y

Correctly rounded

Correctly rounded

x * y

Correctly rounded

Correctly rounded

1.0 / x

Correctly rounded

<= 1 ulp

x / y

Correctly rounded

<= 1 ulp

   

acos

<= 2 ulp

<= 3 ulp

acosh

<= 2 ulp

<= 3 ulp

acospi

<= 2 ulp

<= 3 ulp

asin

<= 2 ulp

<= 3 ulp

asinh

<= 2 ulp

<= 3 ulp

asinpi

<= 2 ulp

<= 3 ulp

atan

<= 2 ulp

<= 3 ulp

atanh

<= 2 ulp

<= 3 ulp

atanpi

<= 2 ulp

<= 3 ulp

atan2

<= 2 ulp

<= 3 ulp

atan2pi

<= 2 ulp

<= 3 ulp

cbrt

<= 2 ulp

<= 2 ulp

ceil

Correctly rounded

Correctly rounded

clamp

0 ulp

0 ulp

copysign

0 ulp

0 ulp

cos

<= 2 ulp

<= 2 ulp

cosh

<= 2 ulp

<= 3 ulp

cospi

<= 2 ulp

<= 2 ulp

cross

absolute error tolerance of 'max * max * (3 * HALF_EPSILON)' per vector component, where max is the maximum input operand magnitude

 

每个矢量分量的“max*max*(3*HALF_EPSILON)”的绝对误差容限,其中max是最大输入操作数幅度

Implementation-defined

degrees

<= 2 ulp

<= 2 ulp

distance

<= 2n ulp, for gentype with vector width n

Implementation-defined

dot

absolute error tolerance of 'max * max * (2n - 1) * HALF_EPSILON', for vector width n and maximum input operand magnitude max across all vector components

 

对于所有矢量分量的向量宽度n和最大输入操作数幅度max,'max*max*(2n-1)*HALF_EPSILON'的绝对误差容限

Implementation-defined

erfc

<= 4 ulp

<= 4 ulp

erf

<= 4 ulp

<= 4 ulp

exp

<= 2 ulp

<= 3 ulp

exp2

<= 2 ulp

<= 3 ulp

exp10

<= 2 ulp

<= 3 ulp

expm1

<= 2 ulp

<= 3 ulp

fabs

0 ulp

0 ulp

fdim

Correctly rounded

Correctly rounded

floor

Correctly rounded

Correctly rounded

fma

Correctly rounded

Correctly rounded

fmax

0 ulp

0 ulp

fmin

0 ulp

0 ulp

fmod

0 ulp

0 ulp

fract

Correctly rounded

Correctly rounded

frexp

0 ulp

0 ulp

hypot

<= 2 ulp

<= 3 ulp

ilogb

0 ulp

0 ulp

ldexp

Correctly rounded

Correctly rounded

length

<= 0.25 + 0.5n ulp, for gentype with vector width n

 

<=0.25+0.5n ulp,对于矢量宽度为n的正型

Implementation-defined

log

<= 2 ulp

<= 3 ulp

log2

<= 2 ulp

<= 3 ulp

log10

<= 2 ulp

<= 3 ulp

log1p

<= 2 ulp

<= 3 ulp

logb

0 ulp

0 ulp

mad

Implementation-defined

Implementation-defined

max

0 ulp

0 ulp

maxmag

0 ulp

0 ulp

min

0 ulp

0 ulp

minmag

0 ulp

0 ulp

mix

Implementation-defined

Implementation-defined

modf

0 ulp

0 ulp

nan

0 ulp

0 ulp

nextafter

0 ulp

0 ulp

normalize

<= 1 + n ulp, for gentype with vector width n

 

<=1+n ulp,适用于向量宽度为n的gentype

Implementation-defined

pow(x, y)

<= 4 ulp

<= 5 ulp

pown(x, y)

<= 4 ulp

<= 5 ulp

powr(x, y)

<= 4 ulp

<= 5 ulp

radians

<= 2 ulp

<= 2 ulp

remainder

0 ulp

0 ulp

remquo

0 ulp for the remainder, at least the lower 7 bits of the integral quotient

 

余数为0ulp,至少为整数商的低7位

0 ulp for the remainder, at least the lower 7 bits of the integral quotient

 

余数为0ulp,至少为整数商的低7位

rint

Correctly rounded

Correctly rounded

rootn

<= 4 ulp

<= 5 ulp

round

Correctly rounded

Correctly rounded

rsqrt

<=1 ulp

<=1 ulp

sign

0 ulp

0 ulp

sin

<= 2 ulp

<= 2 ulp

sincos

<= 2 ulp for sine and cosine values

<= 2 ulp for sine and cosine values

sinh

<= 2 ulp

<= 3 ulp

sinpi

<= 2 ulp

<= 2 ulp

smoothstep

Implementation-defined

Implementation-defined

sqrt

Correctly rounded

<= 1 ulp

step

0 ulp

0 ulp

tan

<= 2 ulp

<= 3 ulp

tanh

<= 2 ulp

<= 3 ulp

tanpi

<= 2 ulp

<= 3 ulp

tgamma

<= 4 ulp

<= 4 ulp

trunc

Correctly rounded

Correctly rounded

 

Implementations may perform floating-point operations on half scalar or vector data types by converting the half values to single precision floating-point values and performing the operation in single precision floating-point. In this case, the implementation will use the half scalar or vector data type as a storage only format.

 

通过将half值转换为单精度浮点值并在单精度浮点中执行操作,实现可以对半标量或矢量数据类型执行浮点操作。在这种情况下,实现将使用半标量或矢量数据类型作为仅存储的格式。

7.5. Edge Case Behavior

7.5. 边缘案例行为

The edge case behavior of the math functions shall conform to sections F.9 and G.6 of the C99 Specification, except where noted below.

​数学函数的边缘情况行为应符合C99规范第F.9节和第G.6节的要求,除非下文另有说明。

7.5.1. Additional Requirements Beyond C99 TC2

7.5.1. C99 TC2之外的附加要求

All functions that return a NaN should return a quiet NaN.

所有返回NaN的函数都应该返回一个安静的NaN。

half_<funcname> functions behave identically to the function of the same name without the half_ prefix. They must conform to the same edge case requirements (see sections F.9 and G.6 of the C99 Specification). For other cases, except where otherwise noted, these single precision functions are permitted to have up to 8192 ulps of error (as measured in the single precision result), although better accuracy is encouraged.

​half_<funcname>函数的行为与没有half_前缀的同名函数相同。它们必须符合相同的边缘情况要求(见C99规范第F.9节和第G.6节)。对于其他情况,除非另有说明,否则允许这些单精度函数具有高达8192 ulps的误差(如单精度结果中测量的),尽管鼓励更高的精度。

The usual allowances for rounding error or flushing behavior shall not apply for those values for which section F.9 of the C99 Specification, or the additional requirements and edge case behavior below (and similar sections for other floating-point precisions) prescribe a result (e.g. ceil(-1 < x < 0) returns -0). Those values shall produce exactly the prescribed answers, and no other. Where the ± symbol is used, the sign shall be preserved. For example, sin(±0) = ±0 shall be interpreted to mean sin(+0) is +0 and sin(-0) is -0.

​对于C99规范第F.9节或以下附加要求和边缘情况行为(以及其他浮点精度的类似章节)规定结果(例如ceil(-1<x<0)返回-0)的值,舍入误差或刷新行为的通常容差不适用。这些值应完全产生规定的答案,而不是其他答案。如果使用±符号,则应保留标志。例如,sin(±0)=±0应解释为sin(+0)为+0,sin(-0)为-0。

  • acospi(1) = +0.

  • acospi(x) returns a NaN for |x| > 1.

  • asinpi(±0) = ±0.

  • asinpi(x) returns a NaN for |x| > 1.

  • atanpi(±0) = ±0.

  • atanpi(±∞) = ±0.5.

  • atan2pi(±0, -0) = ±1.

  • atan2pi(±0, +0) = ±0.

  • atan2pi(±0, x) returns ±1 for x < 0.

  • atan2pi(±0, x) returns ±0 for x > 0.

  • atan2pi(y, ±0) returns -0.5 for y < 0.

  • atan2pi(y, ±0) returns 0.5 for y > 0.

  • atan2pi(±_y_, -∞) returns ±1 for finite y > 0.

  • atan2pi(±_y_, +∞) returns ±0 for finite y > 0.

  • atan2pi(±∞, x) returns ±0.5 for finite x.

  • atan2pi(±∞, -∞) returns ±0.75.

  • atan2pi(±∞, +∞) returns ±0.25.

  • ceil(-1 < x < 0) returns -0.

  • cospi(±0) returns 1

  • cospi(n + 0.5) is +0 for any integer n where n + 0.5 is representable.

  • 对于任何整数n,cospi(n+0.5)都是+0,其中n+0.5是可表示的。

  • cospi(±∞) returns a NaN.

  • exp10(-∞) returns +0.

  • exp10(+∞) returns +∞.

  • distance(xy) calculates the distance from x to y without overflow or extraordinary precision loss due to underflow.

  • distance(x,y)计算从x到y的距离,没有溢出或由于下溢导致的异常精度损失。

  • fdim(any, NaN) returns NaN.

  • fdim(NaN, any) returns NaN.

  • fmod(±0, NaN) returns NaN.

  • frexp(±∞, exp) returns ±∞ and stores 0 in exp.

  • frexp(NaN, exp) returns the NaN and stores 0 in exp.

  • fract(xiptr) shall not return a value greater than or equal to 1.0, and shall not return a value less than 0.

  • fract(x,iptr)不应返回大于或等于1.0的值,也不应返回小于0的值。

  • fract(+0, iptr) returns +0 and +0 in iptr.

  • fract(-0, iptr) returns -0 and -0 in iptr.

  • fract(+∞, iptr) returns +0 and +∞ in iptr.

  • fract(-∞, iptr) returns -0 and -∞ in iptr.

  • fract(NaN, iptr) returns the NaN and NaN in iptr.

  • length calculates the length of a vector without overflow or extraordinary precision loss due to underflow.

  • length计算向量的长度,没有溢出或由于下溢导致的异常精度损失。

  • lgamma_r(xsignp) returns 0 in signp if x is zero or a negative integer.

  • 如果x为零或负整数,lgammarr(x,signp)在signp中返回0。

  • nextafter(-0, y > 0) returns smallest positive denormal value.

  • nextafter(-0,y>0)返回最小的正非标准值。

  • nextafter(+0, y < 0) returns smallest negative denormal value.

  • nextafter(+0,y<0)返回最小的负非标准值。

  • normalize shall reduce the vector to unit length, pointing in the same direction without overflow or extraordinary precision loss due to underflow.

  • normalize应将向量减少到单位长度,指向同一方向,而不会因下溢而产生溢出或异常精度损失。

  • normalize(v) returns v if all elements of v are zero.

  • 如果v的所有元素都为零,则normalize(v)返回v。

  • normalize(v) returns a vector full of NaNs if any element is a NaN.

  • normalize(v)如果任何元素是NaN,则返回一个充满NaN的向量。

  • normalize(v) for which any element in v is infinite shall proceed as if the elements in v were replaced as follows:

  • 归一化(v),其中v中的任何元素都是无限的,应按如下方式替换v中的元素:

    for (i = 0; i < sizeof(v) / sizeof(v[0]); i++)
       v[i] = isinf(v[i]) ? copysign(1.0, v[i]) : 0.0 * v[i];
  • pow(±0, -∞) returns +∞

  • pown(x, 0) is 1 for any x, even zero, NaN or infinity.

  • pown(±0, n) is ±∞ for odd n < 0.

  • pown(±0, n) is +∞ for even n < 0.

  • pown(±0, n) is +0 for even n > 0.

  • pown(±0, n) is ±0 for odd n > 0.

  • powr(x, ±0) is 1 for finite x > 0.

  • powr(±0, y) is +∞ for finite y < 0.

  • powr(±0, -∞) is +∞.

  • powr(±0, y) is +0 for y > 0.

  • powr(+1, y) is 1 for finite y.

  • powr(xy) returns NaN for x < 0.

  • powr(±0, ±0) returns NaN.

  • powr(+∞, ±0) returns NaN.

  • powr(+1, ±∞) returns NaN.

  • powr(x, NaN) returns the NaN for x >= 0.

  • powr(NaN, y) returns the NaN.

  • rint(-0.5 <= x < 0) returns -0.

  • remquo(xy, &_quo_) returns a NaN and 0 in quo if x is ±∞, or if y is 0 and the other argument is non-NaN or if either argument is a NaN.

  • remquo(x,y,&_quo_)返回一个NaN和0,如果x是±∞,或者如果y是0,另一个参数是非NaN,或者如果任何一个参数都是NaN。

  • rootn(±0, n) is ±∞ for odd n < 0.

  • rootn(±0, n) is +∞ for even n < 0.

  • rootn(±0, n) is +0 for even n > 0.

  • rootn(±0, n) is ±0 for odd n > 0.

  • rootn(xn) returns a NaN for x < 0 and n is even.

  • rootn(x, 0) returns a NaN.

  • round(-0.5 < x < 0) returns -0.

  • sinpi(±0) returns ±0.

  • sinpi(+n) returns +0 for positive integers n.

  • sinpi(-n) returns -0 for negative integers n.

  • sinpi(±∞) returns a NaN.

  • tanpi(±0) returns ±0.

  • tanpi(±∞) returns a NaN.

  • tanpi(n) is copysign(0.0, n) for even integers n.

  • tanpi(n)是偶数n的copysign(0.0,n)。

  • tanpi(n) is copysign(0.0, - n) for odd integers n.

  • tanpi(n)是奇数n的复制符号(0.0,-n)。

  • tanpi(n + 0.5) for even integer n is +∞ where n + 0.5 is representable.

  • 偶数n的tanpi(n+0.5)为+∞,其中n+0.5是可表示的。

  • tanpi(n + 0.5) for odd integer n is -∞ where n + 0.5 is representable.

  • 奇数n的tanpi(n+0.5)为-∞,其中n+0.5是可表示的。

  • trunc(-1 < x < 0) returns -0. Binary file (standard input) matches

  • trunc(-1<x<0)返回-0。二进制文件(标准输入)匹配

7.5.2. Changes to C99 TC2 Behavior

7.5.2. C99 TC2行为的变化

modf behaves as though implemented by:

modf的行为就像是通过以下方式实现的:

gentype modf(gentype value, gentype *iptr)
{
    *iptr = trunc( value );
    return copysign(isinf( value ) ? 0.0 : value - *iptr, value);
}

rint always rounds according to round to nearest even rounding mode even if the caller is in some other rounding mode.

即使调用者处于其他舍入模式,rint也始终按照舍入到最近偶数舍入模式进行舍入。

7.5.3. Edge Case Behavior in Flush to Zero Mode

7.5.3. 齐平至零模式下的边缘情况行为

If denormals are flushed to zero, then a function may return one of four results:

如果非正规值被刷新为零,则函数可能会返回以下四个结果之一:

1.Any conforming result for non-flush-to-zero mode

1.非冲洗归零模式的任何合格结果

2.If the result given by 1. is a sub-normal before rounding, it may be flushed to zero

2.如果结果由1给出。在四舍五入之前是一个亚正常值,它可能会被冲到零

3.Any non-flushed conforming result for the function if one or more of its sub-normal operands are flushed to zero.

3.如果函数的一个或多个次正态操作数被刷新为零,则函数的任何非刷新一致结果。

4.If the result of 3. is a sub-normal before rounding, the result may be flushed to zero.

4.如果结果为3.如果四舍五入前为亚正常值,则结果可能会被刷新为零。

In each of the above cases, if an operand or result is flushed to zero, the sign of the zero is undefined.

在上述每种情况下,如果操作数或结果被刷新为零,则零的符号未定义。

If subnormals are flushed to zero, a device may choose to conform to the following edge cases for nextafter instead of those listed in the additional requirements section.

​如果亚正常值被清零,设备可以选择符合以下next after的边缘情况,而不是附加要求部分中列出的情况。

  • nextafter(+smallest normal, y < +smallest normal) = +0.

  • nextafter(-smallest normal, y > -smallest normal) = -0.

  • nextafter(-0, y > 0) returns smallest positive normal value.

  • nextafter(-0,y>0)返回最小的正值。

  • nextafter(+0, y < 0) returns smallest negative normal value.

  • nextafter(+0,y<0)返回最小的负正值。

For clarity, subnormals or denormals are defined to be the set of representable numbers in the range 0 < x < TYPE_MIN and -TYPE_MIN < x < -0. They do not include ±0. A non-zero number is said to be sub-normal before rounding if after normalization, its radix-2 exponent is less than (TYPE_MIN_EXP - 1) [114].


为清楚起见,亚正态或非正态被定义为0 < x < TYPE_MIN-TYPE_MIN < x < -0范围内的可表示数字集。它们不包括±0。如果归一化后,非零数字的基2指数小于(TYPE_MIN_EXP - 1)[114],则称其在舍入前为次正态。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值