C++ Standard Library C++ STL Library

C++ <cmath> - tan() Function



The C++ <cmath> tan() function returns trigonometric tangent of an angle (angle should be in radians). In the graph below, tan(x) vs x is plotted.

Tan Function

Syntax

double tan (double x);
float tan (float x);
long double tan (long double x);
double tan (double x);
float tan (float x);
long double tan (long double x);
//additional overloads for integral types
double tan (T x);           

Parameters

x Specify the angle in radian.

Return Value

Returns the trigonometric tangent of an angle.

Example:

In the example below, tan() function is used to find out the trigonometric tangent of an angle.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  //M_PI - value of PI from math.h
  cout<<tan(M_PI/6)<<"\n";
  cout<<tan(M_PI/4)<<"\n";
  cout<<tan(M_PI/3)<<"\n";
  return 0;
}

The output of the above code will be:

0.57735
1
1.73205

❮ C++ <cmath> Library