Namespaces
Variants

tan, tanf, tanl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
Definiert im Header <math.h>
float tanf ( float arg ) ;
(1) (seit C99)
double tan ( double arg ) ;
(2)
long double tanl ( long double arg ) ;
(3) (seit C99)
_Decimal32  tand32 ( _Decimal32 arg ) ;
(4) (seit C23)
_Decimal64  tand64 ( _Decimal64 arg ) ;
(5) (seit C23)
_Decimal128 tand128 ( _Decimal128 arg ) ;
(6) (seit C23)
Definiert im Header <tgmath.h>
#define tan( arg )
(7) (seit C99)
1-6) Berechnet den Tangens von arg (gemessen in Radiant).
7) Typgenerisches Makro: Wenn das Argument den Typ long double hat, (3) ( tanl ) wird aufgerufen. Andernfalls, wenn das Argument einen ganzzahligen Typ oder den Typ double hat, (2) ( tan ) wird aufgerufen. Andernfalls (1) ( tanf ) wird aufgerufen. Wenn das Argument komplex ist, ruft das Makro die entsprechende komplexe Funktion auf ( ctanf , ctan , ctanl ).

Die Funktionen (4-6) werden genau dann deklariert, wenn die Implementierung __STDC_IEC_60559_DFP__ vordefiniert (d.h. die Implementierung unterstützt dezimale Gleitkommazahlen).

(seit C23)

Inhaltsverzeichnis

Parameter

arg - Fließkommawert, der den Winkel im Bogenmaß darstellt

Rückgabewert

Wenn keine Fehler auftreten, wird der Tangens von arg ( tan(arg) ) zurückgegeben.

Das Ergebnis kann wenig oder keine Bedeutung haben, wenn die Größenordnung von arg groß ist.

(bis C99)

Wenn ein Domänenfehler auftritt, wird ein implementierungsdefinierter Wert zurückgegeben (NaN, sofern unterstützt).

Wenn ein Bereichsfehler aufgrund von Unterlauf auftritt, wird das korrekte Ergebnis (nach Rundung) zurückgegeben.

Fehlerbehandlung

Fehler werden gemeldet, wie in math_errhandling spezifiziert.

Wenn die Implementierung IEEE-Gleitkommaarithmetik (IEC 60559) unterstützt:

  • wenn das Argument ±0 ist, wird es unverändert zurückgegeben;
  • wenn das Argument ±∞ ist, wird NaN zurückgegeben und FE_INVALID ausgelöst;
  • wenn das Argument NaN ist, wird NaN zurückgegeben.

Hinweise

Der Fall, in dem das Argument unendlich ist, ist in C nicht als Domänenfehler spezifiziert, aber es ist definiert als ein Domänenfehler in POSIX .

Die Funktion hat mathematische Pole bei π(1/2 + n) ; jedoch ist keine gängige Fließkommadarstellung in der Lage, π/2 exakt darzustellen, daher gibt es keinen Argumentwert, bei dem ein Polfehler auftritt.

Beispiel

#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);
    // Typische Verwendung
    printf("tan(pi*1/4) = %+f\n", tan(pi * 1 / 4)); //   45 Grad
    printf("tan(pi*3/4) = %+f\n", tan(pi * 3 / 4)); //  135 Grad
    printf("tan(pi*5/4) = %+f\n", tan(pi * 5 / 4)); // -135 Grad
    printf("tan(pi*7/4) = %+f\n", tan(pi * 7 / 4)); //  -45 Grad
    // Spezielle Werte
    printf("tan(+0) = %f\n", tan(0.0));
    printf("tan(-0) = %f\n", tan(-0.0));
    // Fehlerbehandlung
    feclearexcept(FE_ALL_EXCEPT);
    printf("tan(INFINITY) = %f\n", tan(INFINITY));
    if (fetestexcept(FE_INVALID))
        puts("    FE_INVALID raised");
}

Mögliche Ausgabe:

tan(pi*1/4) = +1.000000
tan(pi*3/4) = -1.000000
tan(pi*5/4) = +1.000000
tan(pi*7/4) = -1.000000
tan(+0) = 0.000000
tan(-0) = -0.000000
tan(INFINITY) = -nan
    FE_INVALID raised

Referenzen

  • C23-Standard (ISO/IEC 9899:2024):
  • 7.12.4.7 Die tan-Funktionen (S.: TBD)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S.: TBD)
  • F.10.1.7 Die tan-Funktionen (S.: TBD)
  • C17-Standard (ISO/IEC 9899:2018):
  • 7.12.4.7 Die tan-Funktionen (S: 175)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S: 272-273)
  • F.10.1.7 Die tan-Funktionen (S: 378)
  • C11-Standard (ISO/IEC 9899:2011):
  • 7.12.4.7 Die tan-Funktionen (S. 240)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S. 373-375)
  • F.10.1.7 Die tan-Funktionen (S. 519)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.12.4.7 Die tan-Funktionen (S. 220)
  • 7.22 Typgenerische Mathematik <tgmath.h> (S. 335-337)
  • F.9.1.7 Die tan-Funktionen (S. 457)
  • C89/C90-Standard (ISO/IEC 9899:1990):
  • 4.5.2.7 Die tan-Funktion

Siehe auch

(C99) (C99)
berechnet Sinus ( sin(x) )
(Funktion)
(C99) (C99)
berechnet Kosinus ( cos(x) )
(Funktion)
(C99) (C99)
berechnet Arcustangens ( arctan(x) )
(Funktion)
(C99) (C99) (C99)
berechnet den komplexen Tangens
(Funktion)