nextafterf

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

x

Atlas A2 training product/Atlas A2 inference product

x

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

There are two data values x and y:

If y is greater than x, the next representable floating-point value greater than x is returned.

If y is less than x, the next representable floating-point value less than x is returned.

If y is equal to x, x is returned.

Prototype

1
inline float nextafterf(float x, float y)

Parameters

Table 1 Parameters

Parameter

Input/Output

Description

x

Input

Source operand.

y

Input

Source operand.

Returns

  • If x is not equal to y, the next representable floating-point value after x in the y direction is returned.
  • If x is equal to y, x is returned.
  • If either x or y is nan, the return value is nan.
  • If x is +inf and y is not nan, the return value is 3.4028235e+38.
  • If x is -inf and y is not nan, the return value is -3.4028235e+38.

Restrictions

For SIMT programming, this API is not supported.

Header File to Be Included

To use this API, the simt_api/math_functions.h header file must be included.

1
#include "simt_api/math_functions.h"

Examples

For SIMD and SIMT programming:
1
2
3
4
5
6
__simt_vf__ __launch_bounds__(1024) inline void KernelNextAfter(__gm__ float* dst, __gm__ float* x, __gm__ float* y)
{
    int idx = threadIdx.x + blockIdx.x * blockDim.x;
    dst[idx] = nextafterf(x[idx], y[idx]);
    printf("x[%d] = %f, y[%d] = %f, dst[%d] = %f, the hexadecimal representation of the input x: 0x%x, the hexadecimal representation of the output dst: 0x%x\n", idx, x[idx], idx, y[idx], idx, dst[idx], x[idx], dst[idx]);
}

The program input is as follows:

1
2
x:[10.0f 10.0f -10.0f -10.0f ...]
y:[20.0f -20.0f 20.0f -20.0f ...]

When the first four threads of the program are running, you will see the following print effect:

1
2
3
4
x[0] = 10.000000, y[0] = 20.000000, dst[0] = 10.000001, the hexadecimal representation of the input x: 0x41200000, the hexadecimal representation of the output dst: 0x41200001
x[1] = 10.000000, y[1] = -20.000000, dst[1] = 9.999999, the hexadecimal representation of the input x: 0x41200000, the hexadecimal representation of the output dst: 0x411fffff
x[2] = -10.000000, y[2] = 20.000000, dst[2] = -9.999999, the hexadecimal representation of the input x: 0xc1200000, the hexadecimal representation of the output dst: 0xc11fffff
x[3] = -10.000000, y[3] = -20.000000, dst[3] = -10.000001, the hexadecimal representation of the input x: 0xc1200000, the hexadecimal representation of the output dst: 0xc1200001