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(), and tanl() shall return 0.0, or β€” if IEC 60559 Floating-Point is not supported β€” an implementation-defined value no greater in magnitude than DBL_MIN, FLT_MIN, and LDBL_MIN, respectively.
  • if x is NaN, a NaN shall be returned.
  • if x is Β±0, x shall be returned.
  • if x is subnormal, a range error may occur and x should be returned.
  • if x is not returned, tan(), tanf(), and tanl() shall return an implementation-defined value no greater in magnitude than DBL_MIN, FLT_MIN, and LDBL_MIN, respectively.
  • if x is Β±Inf, a domain error shall occur, and either a NaN (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(), and tanl() 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 Ο€/2 or is far from 0.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>


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 🫢✨πŸ’