COS(3P)

πŸ’– COS(3P) πŸ’–

okay bestie, buckle UP, because we're doing trigonometry and it's lowkey the cutest thing in the whole POSIX Programmer's Manual. this is the cos page β€” cosine function β€” from the POSIX Programmer's Manual, and yes she's iconic, she's math, she's giving "I peaked in high school geometry" but in the best way. 🌸


✨ PROLOG

real talk first, bestie: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so if you're on Linux, go consult the corresponding Linux manual page for the details, okay?? don't come for me), or β€” plot twist β€” the interface may not be implemented on Linux at all. πŸ’€


🌈 NAME

cos, cosf, cosl β€” cosine function. that's it. that's the whole name. three little functions, one big vibe. πŸ‘‘


πŸŽ€ SYNOPSIS

#include <math.h>

double cos(double x);
float cosf(float x);
long double cosl(long double x);

look at her. three flavors of the exact same energy. double girlie, float girlie, and long double girlie who is highkey extra and we love her for it. πŸ’…


πŸ¦‹ DESCRIPTION

so the functionality described on this reference page is aligned with the ISO C standard. if there's any conflict between the requirements described here and the ISO C standard, that conflict is unintentional β€” no drama intended, fr fr. this volume of POSIX.1‐2017 defers to the ISO C standard, periodt.

these functions shall compute the cosine of their argument x, measured in radians. yes, radians. not degrees. don't do degrees. we'll get to that. πŸ™ˆ

now here's the part where you gotta be a responsible main character: an application wishing to check for error situations should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. on return, if errno is non-zero, or if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, then an error has occurred. that's the vibe check right there. ✨


πŸ’– RETURN VALUE

upon successful completion, these functions shall return the cosine of x. slay.

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

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. (translation: the boring-but-useful bonus content, bestie 🫢)

πŸ“ EXAMPLES

Taking the Cosine of a 45-Degree Angle

#include <math.h>
...
double radians = 45 * M_PI / 180;
double result;
...
result = cos(radians);

see?? that's how you convert degrees to radians. 45 * M_PI / 180. memorize it, screenshot it, put it on your lockscreen. πŸ“±βœ¨


🧚 APPLICATION USAGE

heads up bestie, these functions may lose accuracy when their argument is near an odd multiple of Ο€/2 or is far from 0. it's not her fault, it's just math being math. 😭

and on error, the expressions (math_errhandling & MATH_ERRNO) and (math_errhandling & MATH_ERREXCEPT) are independent of each other, but at least one of them must be non-zero. they're like two besties who don't text each other but are always at the same party. πŸ’œ


🌸 RATIONALE

None.

(not me hyping up an empty section. she said nothing and she said it with her whole chest. iconic. πŸ’…)


⭐ FUTURE DIRECTIONS

None.

(same energy. no notes. πŸ‘‘)


πŸ’« SEE ALSO

  • acos()
  • feclearexcept()
  • fetestexcept()
  • isnan()
  • sin()
  • tan()

The Base Definitions volume of POSIX.1‐2017, Section 4.20, Treatment of Error Conditions for Mathematical Functions, <math.h>

go read the whole trig friend group, they're all serving. 🌈


okay legal bestie moment, we gotta do this part properly:

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 page, bestie!! brought to you by IEEE/The Open Group, dated 2017, filed under COS(3P) in the POSIX Programmer's Manual. go compute some cosines, stay in radians, and remember β€” near odd multiples of Ο€/2 she gets a lil imprecise and that's okay. love u, bye!! πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from