trunc, truncf, truncl
Determines the nearest integer that is less than or equal to the specified floating-point value.
double trunc( double x ); float trunc( float x ); //C++ only long double truncl( long double x );
long double trunc( long double x ); //C++ only float trunc( float x ); //C++ only
The value to truncate.
If successful, returns an integer value of x, rounded towards zero.
Otherwise, may return one of the following:
|x = ±INFINITY||x|
|x = ±0||x|
|x = NaN||NaN|
Errors are reported as specified in _matherr.
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.
|Function||C header||C++ header|
|trunc, truncf, truncl||<math.h>||<cmath>|
For additional compatibility information, see Compatibility.
Send feedback about: