tan(), tanf(), tanl() — Calculate tangent

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both  

Format

#include <math.h>

double tan(double x);
float tan(float x);                  /* C++ only */
long double tan(long double x);      /* C++ only */
float tanf(float x);
long double tanl(long double x);

General description

Calculates the tangent of x, where x is expressed in radians. If x is large, a partial loss of significance in the result can occur.
Note: These functions work in both IEEE Binary Floating-Point and hexadecimal floating-point formats. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.

Returned value

Returns the calculated tangent of x.

If the correct value would cause an underflow, 0 is returned. If the result overflows, ±HUGE_VAL is returned. For both an underflow and an overflow, the value ERANGE is stored in errno.

Special behavior for XPG4.2: The following error is added:
Error Code
Description
EDOM
The argument exceeded an internal limit for the function (approximately 250).

Example

CELEBT01
⁄* CELEBT01                                      

   This example computes x as the tangent of PI⁄4.                              

 *⁄                                                                             
#include <math.h>                                                               
#include <stdio.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
   double pi, x;                                                                
                                                                                
   pi = 3.1415926;                                                              
   x = tan(pi⁄4.0);                                                             
                                                                                
   printf("tan( %lf ) is %lf\n", pi⁄4, x);                                      
}                                                                               
Output
tan( 0.785398 ) is 1.000000

Related information