| 1 |
'\" t |
| 2 |
.\" Copyright 2001, Andries E. Brouwer <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH trunc 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
trunc, truncf, truncl \- round to integer, toward zero |
| 10 |
.SH LIBRARY |
| 11 |
Math library |
| 12 |
.RI ( libm ,\~ \-lm ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <math.h> |
| 16 |
.P |
| 17 |
.BI "double trunc(double " x ); |
| 18 |
.BI "float truncf(float " x ); |
| 19 |
.BI "long double truncl(long double " x ); |
| 20 |
.fi |
| 21 |
.P |
| 22 |
.RS -4 |
| 23 |
Feature Test Macro Requirements for glibc (see |
| 24 |
.BR feature_test_macros (7)): |
| 25 |
.RE |
| 26 |
.P |
| 27 |
.BR trunc (), |
| 28 |
.BR truncf (), |
| 29 |
.BR truncl (): |
| 30 |
.nf |
| 31 |
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
| 32 |
.fi |
| 33 |
.SH DESCRIPTION |
| 34 |
These functions round |
| 35 |
.I x |
| 36 |
to the nearest integer value that is not larger in magnitude than |
| 37 |
.IR x . |
| 38 |
.SH RETURN VALUE |
| 39 |
These functions return the rounded integer value, in floating format. |
| 40 |
.P |
| 41 |
If |
| 42 |
.I x |
| 43 |
is integral, infinite, or NaN, |
| 44 |
.I x |
| 45 |
itself is returned. |
| 46 |
.SH ERRORS |
| 47 |
No errors occur. |
| 48 |
.SH ATTRIBUTES |
| 49 |
For an explanation of the terms used in this section, see |
| 50 |
.BR attributes (7). |
| 51 |
.TS |
| 52 |
allbox; |
| 53 |
lbx lb lb |
| 54 |
l l l. |
| 55 |
Interface Attribute Value |
| 56 |
T{ |
| 57 |
.na |
| 58 |
.nh |
| 59 |
.BR trunc (), |
| 60 |
.BR truncf (), |
| 61 |
.BR truncl () |
| 62 |
T} Thread safety MT-Safe |
| 63 |
.TE |
| 64 |
.SH STANDARDS |
| 65 |
C11, POSIX.1-2008. |
| 66 |
.SH HISTORY |
| 67 |
glibc 2.1. |
| 68 |
C99, POSIX.1-2001. |
| 69 |
.SH NOTES |
| 70 |
The integral value returned by these functions may be too large |
| 71 |
to store in an integer type |
| 72 |
.RI ( int , |
| 73 |
.IR long , |
| 74 |
etc.). |
| 75 |
To avoid an overflow, which will produce undefined results, |
| 76 |
an application should perform a range check on the returned value |
| 77 |
before assigning it to an integer type. |
| 78 |
.SH SEE ALSO |
| 79 |
.BR ceil (3), |
| 80 |
.BR floor (3), |
| 81 |
.BR lrint (3), |
| 82 |
.BR nearbyint (3), |
| 83 |
.BR rint (3), |
| 84 |
.BR round (3) |