trunc(3)
β¨ trunc(3) β the "round toward zero" girlies β¨
okay so this is trunc(3) from the Library Functions Manual, and bestie, she is so much simpler than she looks, I promise π
πΈ NAME πΈ
trunc, truncf, truncl β round to integer, toward zero π«Ά
π LIBRARY π
Math library β that's libm, and you link her with -lm β¨
π SYNOPSIS π
#include <math.h>
double trunc(double x);
float truncf(float x);
long double truncl(long double x);
π Feature Test Macro Requirements for glibc π
(if you don't know what these are, go read feature_test_macros(7), no cap)
trunc(), truncf(), truncl():
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
π DESCRIPTION π
So basically: these functions round x to the nearest integer value that is not larger in magnitude than x. That's the whole job. That's her whole thing. She rounds toward zero, which means she chops off the fractional part and does not care what it was. 2.9? Girl, you're 2.0 now. -2.9? Also -2.0. Toward zero, always toward zero, periodt π
π RETURN VALUE π
She hands you back the rounded integer value β in floating format, mind you. She's not giving you an int. Don't get it twisted π
And if x is already integral, or it's infinite, or it's NaN? She just gives you x right back. Iconic behaviour honestly, no notes π
π ERRORS π
None. Zero. She does not fail. She does not miss. No errors occur. π§β¨
π ATTRIBUTES π
For what all these fancy words even mean, go check attributes(7) bestie.
- Interface:
trunc(),truncf(),truncl()- Attribute: Thread safety
- Value:
MT-Safeπ₯
(aka: she's safe to use across threads, you can absolutely run her in your group chat of threads simultaneously π )
β STANDARDS β
C11, POSIX.1-2008. She's official, she's certified, she's on the syllabus π
π¦ HISTORY π¦
Came into the world in glibc 2.1. She's been standards-approved since C99 and POSIX.1-2001. A true elder icon π
π NOTES π
okay this part actually matters, listen up bestie β
The integral value returned by these functions may be too large to store in an integer type (int,long, etc.). To avoid an overflow, which will produce undefined results, an application should perform a range check on the returned value before assigning it to an integer type. π
likeβ¦ she'll happily hand you a float that's way bigger than any int can hold, and if you just slam it into an int anyway, that's on you and the results are undefined. Range check first. Always. It's giving "look before you leap" fr fr π
π SEE ALSO π
and that's the whole page, bestie!! π this was brought to you by Linux man-pages 6.20, dated 2026-02-08 β so like, she's fresh, she's current, she's living her best life, and now so are you β¨π slay, go round some numbers toward zero π¦π
π¦ where this page comes from
- 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 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2001, Andries E. Brouwer <aeb@cwi.nl>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms