ACOS(3POSIX)

πŸ’– ACOS β€” arc cosine, but make it a vibe πŸ’–

okay bestie, so this one is ACOS(3POSIX) from the POSIX Programmer's Manual, and before we even get into it, there's some housekeeping.

✨ PROLOG ✨

So like, this manual page is part of the POSIX Programmer's Manual. But heads up: the Linux implementation of this interface may differ β€” so if you're on Linux, go consult the corresponding Linux manual page for the actual tea. Or honestly, the interface might just not be implemented on Linux at all. Rude, but okay. 🫠


🌸 NAME 🌸

acos, acosf, acosl β€” arc cosine functions. That's the whole squad. Three of them. All doing arc cosine, just in different flavors. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <math.h>

double acos(double x);
float acosf(float x);
long double acosl(long double x);

Look at that. Gorgeous. Three functions, one header, zero drama. ✨

πŸ’œ DESCRIPTION πŸ’œ

Okay so real talk: everything 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 was not intentional, bestie. This volume of POSIX.1-2017 fully defers to the ISO C standard. ISO C is the main character here, we're just supporting cast. πŸ‘‘

So what do these functions actually do? They compute the principal value of the arc cosine of their argument x. And the value of x should be in the range [-1,1]. That's the vibe check. Stay in range.

Now β€” if you're the type of application that wants to actually check for error situations (responsible queen behavior, honestly), here's the ritual:

  • set errno to zero
  • call feclearexcept(FE_ALL_EXCEPT)
  • then call these functions

And when they come back? If errno is non-zero, or if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero β€” an error has occurred. No cap. 😀


πŸ”₯ RETURN VALUE πŸ”₯

Upon successful completion, these functions shall return the arc cosine of x, in the range [0,Ο€] radians. Slay. ✨

Now the messy parts, and yes we're covering all of them:

  • For finite values of x that are not in the range [-1,1], a domain error shall occur, and either a NaN (if supported) or an implementation-defined value shall be returned. Like, pick one, it's your call, but it's happening.
  • If x is NaN, a NaN shall be returned. Fair. Consistent. Iconic.
  • If x is +1, +0 shall be returned. Cute. πŸŽ€
  • If x is Β±Inf, a domain error shall occur, and a NaN shall be returned.

πŸ’€ ERRORS πŸ’€

These functions shall fail if:

  • Domain Error β€” the x argument is finite and is not in the range [-1,1], or is Β±Inf.

And then it splits depending on your setup:

  • If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [EDOM].
  • If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid floating-point exception shall be raised.
The following sections are informative. So like, they're extra credit. Still reading them tho because I love you. 🫢

πŸ“ EXAMPLES πŸ“

None. 😭 Not a single example. We get nothing. Moving on.

🌈 APPLICATION USAGE 🌈

On error, the expressions (math_errhandling & MATH_ERRNO) and (math_errhandling & MATH_ERREXCEPT) are independent of each other β€” like, they don't text each other, they don't coordinate. But at least one of them must be non-zero. That's the rule. Periodt.

🧚 RATIONALE 🧚

None. πŸ’€

⭐ FUTURE DIRECTIONS ⭐

None. πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘

  • cos()
  • feclearexcept()
  • fetestexcept()
  • isnan()

Also the Base Definitions volume of POSIX.1-2017, Section 4.20, Treatment of Error Conditions for Mathematical Functions, and <math.h>. Go read them, bestie, they're all connected. πŸ”—

Okay so legally I have to say all of this and I'm saying it exactly, no edits:

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 from IEEE/The Open Group, dated 2017, filed under ACOS(3POSIX). Now go compute some arc cosine, stay in [-1,1], and hydrate. πŸ’–βœ¨πŸ¦‹