LABS(3POSIX)

πŸ’– LABS(3POSIX) β€” the POSIX Programmer's Manual, bestie edition πŸ’–

okay so before we even get into it: this is labs, llabs, from the POSIX Programmer's Manual. It's filed under LABS(3POSIX), and it is exactly the kind of page that looks scary and is actually just "number, but positive." Let's go. πŸ¦‹


🌸 PROLOG 🌸

This manual page is part of the POSIX Programmer's Manual. Heads up, bestie, real talk:

  • The Linux implementation of this interface may differ β€” so go check the corresponding Linux manual page for the deets on Linux behavior.
  • Or… the interface may not be implemented on Linux at all.

It's giving "read the room before you ship." πŸ’…


✨ NAME ✨

labs, llabs β€” return a long integer absolute value

(Yes that's both of them in one NAME line. They're a duo. Main characters. πŸ‘‘)


πŸŽ€ SYNOPSIS πŸŽ€

#include <stdlib.h>

long labs(long i);
long long llabs(long long i);

Look at that. Clean. Minimal. Ate. πŸ”₯


πŸ’œ DESCRIPTION πŸ’œ

So the functionality described on this reference page is aligned with the ISO C standard. And if there's any conflict between what's written here and the ISO C standard? That conflict is unintentional β€” this volume of POSIX.1‐2017 defers to the ISO C standard. No drama, the ISO C standard is the authority here. periodt.

Now the actual tea:

  • The labs() function shall compute the absolute value of the long integer operand i.
  • The llabs() function shall compute the absolute value of the long long integer operand i.

And here's the important bit, do NOT skip this:

If the result cannot be represented, the behavior is undefined. 😭 So like, know your ranges. This is not the function to be reckless with.

🌈 RETURN VALUE 🌈

  • The labs() function shall return the absolute value of the long integer operand.
  • The llabs() function shall return the absolute value of the long long integer operand.

That's it. That's the whole return section. It does the one thing and it does it well. ⭐


πŸ’€ ERRORS πŸ’€

No errors are defined.

Iconic. Zero notes. Nothing to handle, nothing to check, just vibes. 🧚

The following sections are informative. (So they're the "for your information" part of the page β€” not normative requirements. Keep that in mind.)

πŸ“ EXAMPLES πŸ“

None.

Honestly? Respect. Sometimes the example is just… using it. πŸ™ˆ


🫢 APPLICATION USAGE 🫢

None.


πŸ’… RATIONALE πŸ’…

None.

The rationale is on vacation. It has left the building. We love that for it. ✨


🌸 FUTURE DIRECTIONS 🌸

None.

Nothing's changing. Stable. Consistent. Loyal. Lowkey the ideal function. πŸ’–


πŸ‘‘ SEE ALSO πŸ‘‘

  • abs()
  • The Base Definitions volume of POSIX.1‐2017, <stdlib.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. Like, that's the final boss. That's the source of truth.

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 and that's the whole page, bestie!! πŸŽ€ big love to IEEE/The Open Group, who shipped this in 2017 under the LABS(3POSIX) name β€” absolute legends, no cap. go take the absolute value of something. safely. within range. πŸ’–βœ¨πŸ¦‹