TAN(3POSIX)
π TAN(3POSIX) β the tangent function, bestie edition π
okay so quick heads up before we even start: this page is TAN(3POSIX), straight out of the POSIX Programmer's Manual. pull up a chair, grab a boba, we're doing trigonometry π
β¨ PROLOG β¨
okay so the tea first, and it's important tea:
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 actual deets on Linux behavior. and like, also possible: the interface might just not be implemented on Linux at all. rude, but okay. π
πΈ NAME πΈ
tan, tanf, tanl β tangent function. that's it, that's the girlies. π
π¦ SYNOPSIS π¦
#include <math.h>
double tan(double x);
float tanf(float x);
long double tanl(long double x);
three besties, three flavors of precision. pick your fighter π
β¨ DESCRIPTION β¨
so 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 conflict is unintentional β no drama was meant. this volume of POSIX.1β2017 defers to the ISO C standard, periodt.
these functions shall compute the tangent of their argument x, measured in radians. (radians, bestie. not degrees. we'll get to the degrees thing in EXAMPLES, don't worry. π«Ά)
now, if your application wants to check for error situations, here's the ritual: set errno to 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 β an error has occurred. that's the vibe check right there. β
π RETURN VALUE π
upon successful completion, these functions shall return the tangent of x. slay. β¨
now the messy parts, because there are so many of them, and honestly? every single one matters:
- if the correct value would cause underflow, and it is not representable, a range error may occur, and
tan(),tanf(), andtanl()shall return0.0, or β if IEC 60559 Floating-Point is not supported β an implementation-defined value no greater in magnitude thanDBL_MIN,FLT_MIN, andLDBL_MIN, respectively. - if
xisNaN, aNaNshall be returned. - if
xisΒ±0,xshall be returned. - if
xis subnormal, a range error may occur andxshould be returned. - if
xis not returned,tan(),tanf(), andtanl()shall return an implementation-defined value no greater in magnitude thanDBL_MIN,FLT_MIN, andLDBL_MIN, respectively. - if
xisΒ±Inf, a domain error shall occur, and either aNaN(if supported), or an implementation-defined value shall be returned. - if the correct value would cause underflow, and it is representable, a range error may occur and the correct value shall be returned.
- if the correct value would cause overflow, a range error shall occur and
tan(),tanf(), andtanl()shall returnΒ±HUGE_VAL,Β±HUGE_VALF, andΒ±HUGE_VALL, respectively, with the same sign as the correct value of the function.
π₯ ERRORS π₯
these functions shall fail if:
Domain Error π
the value of x 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.
Range Error π
the result overflows.
if the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [ERANGE]. if the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the overflow floating-point exception shall be raised.
these functions may fail if:
Range Error π«
the result underflows, or the value of x is subnormal.
if the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [ERANGE]. if the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the underflow floating-point exception shall be raised.
fyi bestie: the following sections are informative. not requirements. just vibes and helpful context. π
π EXAMPLES π
Taking the Tangent of a 45-Degree Angle π
#include <math.h>
...
double radians = 45.0 * M_PI / 180;
double result;
...
result = tan (radians);
see? told you we'd get to the degrees-to-radians conversion. converting before you call, like a queen. π
π APPLICATION USAGE π
- there are no known floating-point representations such that, for a normal argument,
tan(x)is either overflow or underflow. iconic behavior honestly. - these functions may lose accuracy when their argument is near a multiple of
Ο/2or is far from0.0. so like... know that. π - 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.
π§ RATIONALE π§
None.
literally nothing. silence. the void. no notes. π
β FUTURE DIRECTIONS β
None.
also nothing. the future is empty. we love a low-maintenance function. π¦
π SEE ALSO π
atan()feclearexcept()fetestexcept()isnan()
the Base Definitions volume of POSIX.1β2017, Section 4.20, Treatment of Error Conditions for Mathematical Functions, <math.h>
π 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 .
and that's the whole page, bestie!! brought to you by IEEE/The Open Group, dated 2017, filed under TAN(3POSIX) β go forth and tangent responsibly π«Άβ¨π
π¦ 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