Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

tan — tangent of an angle

The tan function from <math.h> computes the tangent of an angle in radians. It accepts double and returns double; its argument is not interpreted as degrees.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <math.h>
double tan(double x);

tan(x) from <math.h> returns the tangent of angle x in radians. Both argument and result have type double. The variants tanf and tanl handle float and long double, respectively.

Tangent has singularities at odd multiples of π/2; avoid those neighborhoods in simple numerical tests. N3096 specifies a range error for nonzero x too close to zero.

On implementations conforming to Annex F, tan preserves the sign of zero, while infinite arguments produce NaN and raise FE_INVALID. Do not assume these guarantees for every C implementation.

Examples

#include <math.h>
#include <stdio.h>

int main(void)
{
    volatile double angle = 0.0;
    double result = tan(angle);
    printf("tan(0) == 0: %d\n", result == 0.0);
    return 0;
}

Result

tan(0) == 0: 1

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources