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
xis NaN, a NaN shall be returned. - if
xisΒ±0, the value1.0shall be returned. - if
xisΒ±Inf, a domain error shall occur, and a NaN shall be returned.
π₯ ERRORS
these functions shall fail if:
- Domain Error β the
xargument 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. π
π COPYRIGHT
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
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms