nearbyint, nearbyintf, nearbyintl

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at nearbyint, nearbyintf, nearbyintl1.

Rounds the specified floating-point value to an integer, and returns that value in a floating-point format.

Syntax

double nearbyint(  
   double x  
);  
  
float nearbyint(  
   float x  
); //C++ only  
  
long double nearbyint(  
   long double x  
); //C++ only  
  
float nearbyintf(  
   float x  
);  
  
long double nearbyintl(  
   long double x  
);  
  

Parameters

[in] x
The value to round.

Return Value

If successful, returns x, rounded to the nearest integer, using the current rounding format as defined by fegetround. Otherwise, the function may return one of the following values:

Issue Return
x = ±INFINITY ±INFINITY, unmodified
x = ±0 ±0, unmodified
x = NaN NaN

Errors are not reported through _matherr; specifically, this function does not report any FE_INEXACT exceptions.

Remarks

The primary difference between this function and rint is that this function does not raise the inexact floating point exception.

Because the maximum floating-point values are exact integers, this function will never overflow by itself; rather, the output may overflow the return value, depending on which version of the function you use.

Requirements

Function C header C++ header
nearbyint, nearbyintf, nearbyintl <math.h> <cmath>

For additional compatibility information, see Compatibility.

See Also

Alphabetical Function Reference