trunc, truncf, truncl
Header: <math.h>
1-3) Computes the nearest integer not greater in magnitude than arg.
# Declarations
float truncf( float arg );
(since C99)
double trunc( double arg );
(since C99)
long double truncl( long double arg );
(since C99)
#define trunc( arg )
(since C99)
# Parameters
arg: floating-point value
# Return value
If no errors occur, the nearest integer value not greater in magnitude than arg (in other words, arg rounded towards zero), is returned.
# Notes
FE_INEXACT may be (but isn’t required to be) raised when truncating a non-integer finite value.
The largest representable floating-point values are exact integers in all standard floating-point formats, so this function never overflows on its own; however the result may overflow any integer type (including intmax_t), when stored in an integer variable.
The implicit conversion from floating-point to integral types also rounds towards zero, but is limited to the values that can be represented by the target type.
# Example
#include <math.h>
#include <stdio.h>
int main(void)
{
printf("trunc(+2.7) = %+.1f\n", trunc(+2.7));
printf("trunc(-2.7) = %+.1f\n", trunc(-2.7));
printf("trunc(-0.0) = %+.1f\n", trunc(-0.0));
printf("trunc(-Inf) = %+f\n", trunc(-INFINITY));
}