TRUNC(3P)
π TRUNC(3P) β the trunc, truncf, truncl glow-up π
okay bestie, welcome to the POSIX Programmer's Manual page for trunc, truncf, and truncl β three functions, one vibe, zero decimal places left behind. it's a <math.h> girlie and she's about to chop your floats. βοΈβ¨
πΈ PROLOG πΈ
so like, real talk before we get into it: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so pls go consult the corresponding Linux manual page if you wanna know how Linux actually behaves), or honestly the interface might just not be implemented on Linux at all. no cap. π«
β¨ NAME β¨
trunc, truncf, truncl β round to truncated integer value π
π SYNOPSIS π
#include <math.h>
double trunc(double x);
float truncf(float x);
long double truncl(long double x);
three versions, three sizes, one shared dream of being a whole number. float, double, long double β pick your fighter. π
π¦ DESCRIPTION π¦
bestie the functionality on this reference page is aligned with the ISO C standard. if anything here ever conflicts with the ISO C standard, that was NOT intentional, ok? this volume of POSIX.1β2017 defers to the ISO C standard and that's just the rules. periodt.
so what do these functions actually do? they shall round their argument to the integer value, in floating format, nearest to but no larger in magnitude than the argument. that's the whole thing. it's giving "closest whole number that doesn't overshoot on the magnitude scale." π₯
π RETURN VALUE π
upon successful completion, these functions shall return the truncated integer value. slay.
the result shall have the same sign as x. like, if x was negative, your answer is negative. no flip-flopping. π
βοΈ
- if
xisNaN, aNaNshall be returned. - if
xisΒ±0orΒ±Inf,xshall be returned.
π ERRORS π
literally none. no errors are defined. it's a chill function.
also, heads up: the following sections are informative. iykyk.
π EXAMPLES π
None. π yeah bestie, they left us with nothing. we move.
π§ APPLICATION USAGE π§
okay important stuff, listen up:
- the integral value returned by these functions need not be expressible as an
intmax_t. so like, the return value should be tested before assigning it to an integer type, to avoid the undefined results of an integer overflow. pls pls pls test it first, we do not want undefined behavior in this house. π - these functions may raise the inexact floating-point exception if the result differs in value from the argument. just a lil heads up. β
π RATIONALE π
None. iconic of them honestly.
π FUTURE DIRECTIONS π
None. nothing on the horizon, bestie. stable queen. π
π₯ SEE ALSO π₯
- The Base Definitions volume of
POSIX.1β2017,<math.h>π«Ά
πΈ COPYRIGHT πΈ
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
okay that's the whole page!! this one came from IEEE/The Open Group, dated 2017, and it's filed under TRUNC(3P). k bye bestie, go truncate something responsibly πβ¨ππ¦πΈπ
π«Ά
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms