COS(3POSIX)
π COS(3POSIX) β the POSIX Programmer's Manual, bestie edition π
okay so welcome to cos(3POSIX), from the POSIX Programmer's Manual. let's get into it πΈ
β¨ PROLOG β¨
okay so first things first, bestie, real talk: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β so pls go consult the corresponding Linux manual page for the actual Linux behavior, okay? or, alternatively, the interface might just not be implemented on Linux at all π. no cap, that's a real possibility.
π NAME π
cos, cosf, cosl β the cosine function. it's giving trigonometry, it's giving math girl summer π
β SYNOPSIS β
#include <math.h>
double cos(double x);
float cosf(float x);
long double cosl(long double x);
three icons, three float sizes. we love range π
π¦ DESCRIPTION π¦
so the functionality described on this reference page is aligned with the ISO C standard. and like, if there's any conflict between the requirements described here and the ISO C standard? that's unintentional, 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, i know, i know, i'm sorry, that's just the deal).
and okay, here's the vibe check part for the girlies who want to actually detect errors: an application wishing to check for error situations should:
- set
errnoto zero, and - call
feclearexcept(FE_ALL_EXCEPT)
...before calling these functions. then, 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 check. do the check. π«Ά
π RETURN VALUE π
upon successful completion, these functions shall return the cosine of x. slay.
but the edge cases are where it gets interesting, so let's go case by case:
- if
xisNaN, aNaNshall be returned. (garbage in, garbage out, but make it standardized π) - if
xisΒ±0, the value1.0shall be returned. - if
xisΒ±Inf, a domain error shall occur, and aNaNshall 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, thenerrnoshall be set to[EDOM]. - if the integer expression
(math_errhandling & MATH_ERREXCEPT)is non-zero, then the invalid floating-point exception shall be raised.
- if the integer expression
heads up bestie: the following sections are informative. they're the vibes, not the requirements. π
πΈ EXAMPLES πΈ
Taking the Cosine of a 45-Degree Angle
like yes, radians are the law, but if you've got degrees, you convert. iconic behavior:
#include <math.h>
...
double radians = 45 * M_PI / 180;
double result;
...
result = cos(radians);
look at her go. converting units AND computing cosine. main character energy π
π APPLICATION USAGE π
real talk, these functions may lose accuracy when their argument is near an odd multiple of Ο/2, or is far from 0. so like, don't come for her if precision gets a little wobbly way out there, okay? π
and also, 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. so they don't talk to each other, they just both have to show up. boundaries, honestly π«Ά
π RATIONALE π
None.
(no notes. she said nothing. and that's fine.)
π FUTURE DIRECTIONS π
None.
(also nothing. the future is, apparently, unbothered.)
π¦ SEE ALSO π¦
acos()feclearexcept()fetestexcept()isnan()sin()tan()
and also: the Base Definitions volume of POSIX.1β2017, Section 4.20, Treatment of Error Conditions for Mathematical Functions, and <math.h>. iykyk π
π COPYRIGHT π
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 .
IEEE/The Open Group β 2017 β COS(3POSIX)
and that's the whole page bestie, ty for coming to my ted talk, go compute some cosines, stay in radians, and remember: Β±Inf will NOT be tolerated πβ¨ππ¦πΈπ
π«Ά
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms