TRUNC(3POSIX)
π TRUNC(3POSIX) β the POSIX Programmer's Manual, bestie edition π
okay so first things first, hi, welcome to TRUNC(3POSIX), straight out of the POSIX Programmer's Manual. sit down, grab a snack, we're gonna talk about rounding numbers downward in magnitude and it's gonna be cute.
πΈ PROLOG πΈ
real talk before we start: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly? the interface may not even 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 besties, one job. π
π DESCRIPTION π
the functionality described on this reference page is aligned with the ISO C standard. and listen β if there's any conflict between the requirements described here and the ISO C standard, that conflict is unintentional. this volume of POSIX.1β2017 defers to the ISO C standard. 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 it. that's the whole vibe. it's giving "snip off the decimal part, keep the magnitude smol." βοΈβ¨
π RETURN VALUE π
upon successful completion, these functions shall return the truncated integer value. π
the result shall have the same sign as x. (yes, sign stays. always. iconic behavior.)
if x is NaN, a NaN shall be returned. π
if x is Β±0 or Β±Inf, x shall be returned. like, unchanged. no notes. π
π ERRORS π
no errors are defined. we love a low-drama function. π§
the following sections are informative. (so like, cute to know, not binding, iykyk.)
π EXAMPLES π
None. bestie there is literally nothing here. moving on. π
π APPLICATION USAGE π
okay this part actually matters so pay attention:
the integral value returned by these functions need not be expressible as an intmax_t. so you should test the return value before assigning it to an integer type, otherwise you'll get the undefined results of an integer overflow and we do not want that energy in this house. π¨
also, these functions may raise the inexact floating-point exception if the result differs in value from the argument. noted. π
π¦ RATIONALE π¦
None. nothing to explain, the girlies simply understood it. π
β FUTURE DIRECTIONS β
None. the future is stable, as it should be. π
π₯ 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 referee! the final say! the main character of documents!) 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 . π
and that's the whole page, bestie!! π this lil masterpiece was brought to you by IEEE/The Open Group, 2017 β mwah, love that for us. now go truncate something responsibly. π β¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms