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 x is NaN, a NaN shall be returned.
  • if x is Β±0 or Β±Inf, x shall 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> 🫢

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