TAN(3P)

🌸 PROLOG 🌸

ok so real talk before we dive in bestie πŸ’– this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not even be implemented on Linux. Not me warning you upfront, periodt.


✨ NAME ✨

tan, tanf, tanl β€” tangent function πŸ¦‹


πŸ’… SYNOPSIS πŸ’…

#include <math.h>

double tan(double x);
float tanf(float x);
long double tanl(long double x);

πŸŽ€ DESCRIPTION πŸŽ€

Okay so the functionality described on this reference page is aligned with the ISO C standard. And like, any conflict between the requirements described here and the ISO C standard? Completely unintentional, no cap. This volume of POSIX.1‐2017 defers to the ISO C standard. It's giving ✨deference✨.

These functions shall compute the tangent of their argument x, measured in radians. (Radians bestie, not degrees, don't do it to yourself πŸ™ˆ)

Now, if your app 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 β€” boom, an error has occurred. 🚨


πŸ’– RETURN VALUE πŸ’–

Upon successful completion, these functions shall return the tangent of x. Slay.

If the correct value would cause underflow, and 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 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.

heads up bestie: the following sections are informative. not normative. just vibes and extra 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);

πŸ’œ APPLICATION USAGE πŸ’œ

There are no known floating-point representations such that, for a normal argument, tan(x) is either overflow or underflow. So like, that's a relief honestly 😌

These functions may lose accuracy when their argument is near a multiple of Ο€/2 or is far from 0.0. So watch out for that, the precision will simply not be there. πŸ™ˆ

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, doing their own thing, but one of them has to show up. πŸ’…


πŸ¦‹ RATIONALE πŸ¦‹

None.

(yeah. nothing. iconic of them honestly πŸ‘‘)


⭐ FUTURE DIRECTIONS ⭐

None.


πŸ”₯ 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 .


ok that's the whole thing, love u, go compute some tangents πŸ«ΆπŸ’–

brought to you by IEEE/The Open Group, 2017, and this page is literally TAN(3P) β€” POSIX Programmer's Manual energy, mwah πŸ’‹
πŸ“¦ where this page comes from