trunc, truncf, truncl
Defined in header
float truncf( float arg );
double trunc( double arg );
long double truncl( long double arg );
Defined in header
#define trunc( arg )
arghas type long double,
trunclis called. Otherwise, if
arghas integer type or the type double,
truncis called. Otherwise,
|arg||-||floating point value|
If no errors occur, the nearest integer value not greater in magnitude than
arg (in other words,
arg rounded towards zero), is returned.
Errors are reported as specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
- The current rounding mode has no effect.
argis ±∞, it is returned, unmodified
argis ±0, it is returned, unmodified
- If arg is NaN, NaN is returned
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.
trunc(+2.7) = +2.0 trunc(-2.7) = -2.0 trunc(-0.0) = -0.0 trunc(-Inf) = -inf
- C11 standard (ISO/IEC 9899:2011):
- 220.127.116.11 The trunc functions (p: 253-254)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- F.10.6.8 The trunc functions (p: 528)
- C99 standard (ISO/IEC 9899:1999):
- 18.104.22.168 The trunc functions (p: 234)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- F.9.6.8 The trunc functions (p: 464)
| computes largest integer not greater than the given value |
| computes smallest integer not less than the given value |
| rounds to nearest integer, rounding away from zero in halfway cases |
C++ documentation for trunc