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
xisΒ±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
xis 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>
π 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 .
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
- 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