FABS(3POSIX)

πŸ’– FABS(3POSIX) πŸ’–

okay bestie, so this one lives in the POSIX Programmer's Manual β€” that's the manual name, and the whole page is literally called FABS(3POSIX). it's about fabs and its two glow-up siblings fabsf and fabsl, aka the absolute value girlies. let's get into it πŸŽ€


✨ PROLOG ✨

so like, real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β€” so if something looks off, go consult the corresponding Linux manual page for the deets on Linux behavior. OR the interface might not even be implemented on Linux at all. no cap. πŸ™ˆ


🌸 NAME 🌸

fabs, fabsf, fabsl β€” absolute value function πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <math.h>

double fabs(double x);
float fabsf(float x);
long double fabsl(long double x);

three of them. one for each float size. they're a trio, they're iconic, they ate. πŸ‘‘


πŸ’œ DESCRIPTION πŸ’œ

so here's the thing β€” the functionality described on this reference page is aligned with the ISO C standard. if there's any conflict between what's written here and the ISO C standard? that's unintentional, not a plot twist. this volume of POSIX.1‐2017 defers to the ISO C standard. periodt.

these functions shall compute the absolute value of their argument x, written as |x|. that's it. that's the whole job. take the negative away, it's giving positive main character energy ✨


🌈 RETURN VALUE 🌈

  • upon successful completion, these functions shall return the absolute value of x πŸ’–
  • if x is NaN, a NaN shall be returned 😭
  • if x is Β±0, +0 shall be returned ⭐
  • if x is Β±Inf, +Inf shall be returned πŸ”₯

πŸ“ ERRORS πŸ“

no errors are defined. nothing to see here, it's a clean run bestie 🧚

heads up: the following sections are informative β€” so they're the fun bonus lore, not the hard requirements.

πŸŽ€ EXAMPLES πŸŽ€

🌸 Computing the 1-Norm of a Floating-Point Vector 🌸

this example shows the use of fabs() to compute the 1-norm of a vector, defined like this:

norm1(v) = |v[0]| + |v[1]| + ... + |v[n-1]|

where |x| denotes the absolute value of x, n denotes the vector's dimension, and v[i] denotes the i-th component of v (0≀i<n).

#include <math.h>

double
norm1(const double v[], const int n)
{
    int     i;
    double  n1_v;  /* 1-norm of v */

    n1_v = 0;
    for (i=0; i<n; i++) {
        n1_v += fabs (v[i]);
    }

    return n1_v;
}

look at that loop. it's just vibes and addition. obsessed πŸ’…


πŸ’… APPLICATION USAGE πŸ’…

none. literally nothing. empty. the void. 🫢


🌟 RATIONALE 🌟

none. also nothing. we love a low-effort section that still gets to exist 😭


πŸ¦„ FUTURE DIRECTIONS πŸ¦„

none. the future is unwritten and this section is blank, bestie ✨


πŸ”₯ SEE ALSO πŸ”₯

  • isnan()
  • 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 .


and that's the whole page, bestie 🫢 this one came to you courtesy of IEEE/The Open Group, 2017 β€” the FABS(3POSIX) page, signing off. take the absolute value of your day and slay πŸ’–βœ¨πŸŽ€