tan, tanf, tanl

Header: <math.h>

1-6) Computes the tangent of arg (measured in radians).

# Declarations

float tanf( float arg );

(since C99)

double tan( double arg );
long double tanl( long double arg );

(since C99)

_Decimal32 tand32( _Decimal32 arg );

(since C23)

_Decimal64 tand64( _Decimal64 arg );

(since C23)

_Decimal128 tand128( _Decimal128 arg );

(since C23)

#define tan( arg )

(since C99)

# Parameters

# Return value

If no errors occur, the tangent of arg (tan(arg)) is returned.

# Notes

The case where the argument is infinite is not specified to be a domain error in C, but it is defined as a domain error in POSIX.

The function has mathematical poles at π(1/2 + n); however no common floating-point representation is able to represent π/2 exactly, thus there is no value of the argument for which a pole error occurs.

# Example

#include <errno.h>
#include <fenv.h>
#include <math.h>
#include <stdio.h>
 
#ifndef __GNUC__
#pragma STDC FENV_ACCESS ON
#endif
 
int main(void)
{
    const double pi = acos(-1);
 
    // typical usage
    printf("tan(pi*1/4) = %+f\n", tan(pi * 1 / 4)); //   45 deg
    printf("tan(pi*3/4) = %+f\n", tan(pi * 3 / 4)); //  135 deg
    printf("tan(pi*5/4) = %+f\n", tan(pi * 5 / 4)); // -135 deg
    printf("tan(pi*7/4) = %+f\n", tan(pi * 7 / 4)); //  -45 deg
 
    // special values
    printf("tan(+0) = %f\n", tan(0.0));
    printf("tan(-0) = %f\n", tan(-0.0));
 
    // error handling
    feclearexcept(FE_ALL_EXCEPT);
    printf("tan(INFINITY) = %f\n", tan(INFINITY));
    if (fetestexcept(FE_INVALID))
        puts("    FE_INVALID raised");
}

# See also