std::tan,st...f,std::tanl(3)
πΈ std::tan, std::tanf, std::tanl π
okay bestie, so this one lives in the C++ Standard Library and it's the trig girlie you already know β she takes an angle and gives you back the tangent. Let's get into it β¨
β¨ NAME β¨
std::tan, std::tanf, std::tanl β literally just std::tan, std::tanf, and std::tanl. that's the whole name, no notes π
π¦ Synopsis π¦
okay so the way this is laid out β everything's Defined in header <cmath>, and there are a few flavours of her. deep breath, we're getting through all of them π
Defined in header <cmath>
float tan ( float num );
double tan ( double num ); (until C++23)
long double tan ( long double num );
/* floating-point-type */ (since C++23)
tan ( /* floating-point-type */ num ); (constexpr since C++26)
float tanf( float num ); (1) (2) (since C++11)
(constexpr since C++26)
long double tanl( long double num ); (3) (since C++11)
(constexpr since C++26)
Additional overloads (since C++11)
Defined in header <cmath>
template< class Integer > (A) (constexpr since C++26)
double tan ( Integer num );
- 1-3) Computes the tangent of num (measured in radians, not degrees, we've been over this π).
- The library provides overloads of
std::tanfor all cv-unqualified floating-point types as the type of the parameter. (since C++23) - A) Additional overloads are provided for all integer types, which are treated as
double. (since C++11)
π Parameters π
numβ floating-point or integer value representing the angle in radians π
π Return value π
so if nothing goes wrong, you get the tangent of num, i.e. tan(num). iconic, no drama. β¨
(until C++11) ngl the result may have little or no significance if the magnitude of num is large. she's doing her best but the math is not mathing at that scale π
- If a domain error occurs, an implementation-defined value is returned (NaN where supported).
- If a range error occurs due to underflow, the correct result (after rounding) is returned.
π₯ Error handling π₯
Errors are reported as specified in math_errhandling. periodt.
If the implementation supports IEEE floating-point arithmetic (IEC 60559), then:
- if the argument is
Β±0, it is returned unmodified π - if the argument is
Β±β, NaN is returned andFE_INVALIDis raised π - if the argument is NaN, NaN is returned π«Ά
π§ Notes π§
okay the lore here is genuinely wild, sit down π
The case where the argument is infinite is not specified to be a domain error in C (to which C++ defers), but it is defined as a domain error in POSIX. so like, depends who you ask, iykyk.
The function has mathematical poles at Ο(1/2 + n) β but no common floating-point representation is able to represent Ο/2 exactly, so there is no value of the argument for which a pole error occurs. like she simply cannot be caught slipping ππ
The additional overloads are not required to be provided exactly as (A). They only need to be sufficient to ensure that for their argument num of integer type, std::tan(num) has the same effect as std::tan(static_cast<double>(num)). just vibe-equivalent, that's the requirement π
π Example π
// Run this code
#include <cerrno>
#include <cfenv>
#include <cmath>
#include <iostream>
// #pragma STDC FENV_ACCESS ON
const double pi = std::acos(-1); // or C++20's std::numbers::pi
int main()
{
// typical usage
std::cout << "tan(1*pi/4) = " << std::tan(1*pi/4) << '\n' // 45Β°
<< "tan(3*pi/4) = " << std::tan(3*pi/4) << '\n' // 135Β°
<< "tan(5*pi/4) = " << std::tan(5*pi/4) << '\n' // -135Β°
<< "tan(7*pi/4) = " << std::tan(7*pi/4) << '\n'; // -45Β°
// special values
std::cout << "tan(+0) = " << std::tan(0.0) << '\n'
<< "tan(-0) = " << std::tan(-0.0) << '\n';
// error handling
std::feclearexcept(FE_ALL_EXCEPT);
std::cout << "tan(INFINITY) = " << std::tan(INFINITY) << '\n';
if (std::fetestexcept(FE_INVALID))
std::cout << " FE_INVALID raised\n";
}
And the output she gives you:
tan(1*pi/4) = 1
tan(3*pi/4) = -1
tan(5*pi/4) = 1
tan(7*pi/4) = -1
tan(+0) = 0
tan(-0) = -0
tan(INFINITY) = -nan
FE_INVALID raised
like look at -0 and -nan β she's serving detail πβ¨
π See also π
the whole friend group, bestie, we're not leaving anyone out π
sin,sinf,sinlβ computes sine (sin(x)) (function) (C++11) (C++11)cos,cosf,coslβ computes cosine (cos(x)) (function) (C++11) (C++11)atan,atanf,atanlβ computes arc tangent (arctan(x)) (function) (C++11) (C++11)tan(std::complex)β computes tangent of a complex number (tan(z)) (function template)tan(std::valarray)β applies the functionstd::tanto each element of valarray (function template)- C documentation for
tanβ the og, the blueprint π«‘
and that's the whole page, bestie β no cap, every flag and footnote accounted for π
πΈ source/version + date, respectfully: http://cppreference.com, 2024.06.10, and this whole thing is filed under std::tan,st...f,std::tanl(3). mwah π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms