Developer Guide and Reference

ID 767253
Date 10/31/2024
Public
Document Table of Contents

IMF Device Library Rounding Functions

The IMF Device Library supports the following rounding functions:

ceil

Description: The ceil(x) function computes an integer value rounded towards plus infinity for an x argument.

Special Values:

Argument x Result ceil(x)
+/-∞ +/-∞
-1.5 -1
+/-0 +0
+1.5 +2

Calling Interfaces:

Default accuracy:

float       sycl::ext::intel::math::ceil ( float x );
double      sycl::ext::intel::math::ceil ( double x );

floor

Description: The floor(x) function computes an integer value rounded towards minus infinity for an x argument.

Special Values:

Argument x Result floor(x)
+/-∞ +/-∞
-1.5 -2
+/-0 +0
+1.5 +1

Calling Interfaces:

Default accuracy:

float       sycl::ext::intel::math::floor ( float x );
double      sycl::ext::intel::math::floor ( double x );

llrint

Description: The llrint(x) function computes an integer value in the executing device's current rounding mode for a given argument x that returns the value as a long long int type.

On Linux, llrint(x) is technically the same as lrint(x) since long int is the same 64-bit data type as long long int.

On Windows, llrint(x) and lrint(x) are different because long int is a 32-bit type while long long int is 64-bit one.

Special Values:

Argument x Result llrint(x)
+/-∞ +/-∞
-3.5 -4
-2.5 -2
-1.5 -2
-0.5 -0
+/-0 +0
+0.5 +0
+1.5 +2
+2.5 +2
+3.5 +4
NOTE:
Here the llrint(x) results are presented for rounding mode that is set to the nearest integer.

Calling Interfaces:

Default accuracy:

long long int      sycl::ext::intel::math::llrint ( float x );
ling long int      sycl::ext::intel::math::llrint ( double x );

llround

Description: The llround(x) function computes a value rounded to the nearest integer for an x argument and returns the value in a long long int type

The function computes a value rounded to the nearest integer for each vector element. Input elements that are halfway between two consecutive integers are always rounded away from zero regardless of the rounding mode.

On Linux, llround(x) is technically the same as lround(x) since long int is the same 64-bit data type as long long int.

On Windows, llround(x) and lround(x) are different because long int is a 32-bit type while long long int is 64-bit one.

Special Values:

Argument x Result llround(x)
+/-∞ +/-∞
-1.5 -2
+/-0 +0
+1.5 +2

Calling Interfaces:

Default accuracy:

long long int      sycl::ext::intel::math::llround ( float x );
long long int      sycl::ext::intel::math::llround ( double x );

lrint

Description: The lrint(x) function computes an integer value in the executing device's current rounding mode for a given argument of x that returns the value as a long int type.

On Linux, lrint(x) is technically the same as llrint(x) since long int is the same 64-bit data type as long long int.

On Windows, lrint(x) and llrint(x) are different because long int is a 32-bit type while long long int is 64-bit one.

Special Values:

Argument x Result lrint(x)
+/-∞ +/-∞
-3.5 -4
-2.5 -2
-1.5 -2
-0.5 -0
+/-0 +0
+0.5 +0
+1.5 +2
+2.5 +2
+3.5 +4
NOTE:
Here the lrint(x) results are presented for a rounding mode set to the nearest integer.

Calling Interfaces:

Default accuracy:

long int      sycl::ext::intel::math::lrint ( float x );
long int      sycl::ext::intel::math::lrint ( double x );

lround

Description: The lround(x) function computes a value rounded to the nearest integer for a given argument of x that returns the value as a long int type

The function computes a value rounded to the nearest integer for each vector element. Input elements that are halfway between two consecutive integers are always rounded away from zero regardless of the rounding mode.

On Linux, lround(x) is technically the same as llround(x) since long int is the same 64-bit data type as long long int.

On Windows, lround(x) and llround(x) are different because long int is a 32-bit type while long long int is 64-bit one.

Special Values:

Argument x Result lround(x)
+/-∞ +/-∞
-1.5 -2
+/-0 +0
+1.5 +2

Calling Interfaces:

Default accuracy:

long int      sycl::ext::intel::math::lround ( float x );
long int      sycl::ext::intel::math::lround ( double x );

nearbyint

Description: The nearbyint(x) function computes an integer value in the executing device's current rounding mode for an x argument.

According to the standard, nearbyint(x) never raises an FE_INEXACT exception, while rint(x) does in exceptional cases. Floating-point exceptions are not supported on platforms supported by IMF Device Library, therefore, technically, nearbyint(x) is the same as rint(x) implementation.

Special Values:

Argument x Result nearbyint(x)
+/-∞ +/-∞
-3.5 -4
-2.5 -2
-1.5 -2
-0.5 -0
+/-0 +0
+0.5 +0
+1.5 +2
+2.5 +2
+3.5 +4
NOTE:
Here the nearbyint(x) results are presented for a rounding mode set to the nearest integer.

Calling Interfaces:

Default accuracy:

float       sycl::ext::intel::math::nearbyint ( float x );
double      sycl::ext::intel::math::nearbyint ( double x );

rint

Description: The rint(x) function computes an integer value in the executing device's current rounding mode for an x argument.

Special Values:

Argument x Result rint(x)
+/-∞ +/-∞
-3.5 -4
-2.5 -2
-1.5 -2
-0.5 -0
+/-0 +0
+0.5 +0
+1.5 +2
+2.5 +2
+3.5 +4
NOTE:
Here the rint(x) results are presented for a rounding mode set to the nearest integer.

Calling Interfaces:

Default accuracy:

float       sycl::ext::intel::math::rint ( float x );
double      sycl::ext::intel::math::rint ( double x );

round

Description: The round(x) function computes a value rounded to the nearest integer for an x argument

The function computes a value rounded to the nearest integer for each vector element. Input elements that are halfway between two consecutive integers are always rounded away from zero regardless of the rounding mode.

Special Values:

Argument x Result round(x)
+/-∞ +/-∞
-1.5 -2
+/-0 +0
+1.5 +2

Calling Interfaces:

Default accuracy:

float       sycl::ext::intel::math::round ( float x );
double      sycl::ext::intel::math::round ( double x );

trunc

Description: The trunc(x) function computes an integer value rounded towards zero for an x argument.

Special Values:

Argument x Result trunc(x)
+/-∞ +/-∞
-1.5 -1
+/-0 +0
+1.5 +1

Calling Interfaces:

Default accuracy:

float       sycl::ext::intel::math::trunc ( float x );
double      sycl::ext::intel::math::trunc ( double x );