Share via


trunc, truncf, truncl

 

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 trunc, truncf, truncl.

Determines the nearest integer that is less than or equal to the specified floating-point value.

Syntax

double trunc(  
   double x  
);  
  
float trunc(  
   float x  
); //C++ only  
  
long double trunc(  
   long double x  
); //C++ only  
  
float trunc(  
   float x  
); //C++ only  
  
long double truncl(  
   long double x  
);  
  

Parameters

[in] x
The value to truncate.

Return Value

If successful, returns an integer value of x, rounded towards zero.

Otherwise, may return one of the following:

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

Errors are reported as specified in _matherr.

Remarks

Because C++ allows overloading, you can call overloads of trunc that take and return float and long double types. In a C program, trunc always takes and returns a double.

Because the largest floating-point values are exact integers, this function will not overflow on its own. However, you may cause the function to overflow by returning a value into an integer type.

You can also round down by implicitly converting from floating-point to integral; however, doing so is limited to the values that can be stored in the target type.

Requirements

Function C header C++ header
trunc, truncf, truncl <math.h> <cmath>

For additional compatibility information, see Compatibility.

See Also

Alphabetical Function Reference
floor, floorf, floorl
ceil, ceilf, ceill
round, roundf, roundl