Namespaces
Variants

atan2, atan2f, atan2l

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 in Header <math.h>
float atan2f ( float y, float x ) ;
(1) (seit C99)
double atan2 ( double y, double x ) ;
(2)
long double atan2l ( long double y, long double x ) ;
(3) (seit C99)
_Decimal32  atan2d32 ( _Decimal32 y, _Decimal32 x ) ;
(4) (seit C23)
_Decimal64  atan2d64 ( _Decimal64 y, _Decimal64 x ) ;
(5) (seit C23)
_Decimal128 atan2d128 ( _Decimal128 y, _Decimal128 x ) ;
(6) (seit C23)
Definiert in Header <tgmath.h>
#define atan2( y, x )
(7) (seit C99)
1-6) Berechnet den Arkustangens von y / x unter Verwendung der Vorzeichen der Argumente zur Bestimmung des korrekten Quadranten.
7) Typgenerisches Makro: Wenn ein Argument den Typ long double hat, (3) ( atan2l ) wird aufgerufen. Andernfalls, wenn ein Argument ganzzahligen Typ oder den Typ double hat, (2) ( atan2 ) wird aufgerufen. Andernfalls (1) ( atan2f ) wird aufgerufen.

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

x, y - Gleitkommawert

Rückgabewert

If no errors occur, the arc tangent of y / x ( arctan(
y
x
)
) in the range [-π ; +π] radians, is returned.
Y-Argument
Rückgabewert
X-Argument

Wenn ein Domänenfehler auftritt, wird ein implementierungsdefinierter Wert zurückgegeben.

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

Fehlerbehandlung

Fehler werden gemeldet, wie in math_errhandling festgelegt.

Ein Domänenfehler kann auftreten, wenn x und y beide null sind.

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

  • Wenn x und y beide null sind, tritt kein Domänenfehler auf;
  • Wenn x und y beide null sind, tritt auch kein Wertebereichsfehler auf;
  • Wenn y null ist, tritt kein Polfehler auf;
  • Wenn y ±0 ist und x negativ oder -0 ist, wird ±π zurückgegeben;
  • Wenn y ±0 ist und x positiv oder +0 ist, wird ±0 zurückgegeben;
  • Wenn y ±∞ ist und x endlich ist, wird ±π/2 zurückgegeben;
  • Wenn y ±∞ ist und x -∞ ist, wird ±3π/4 zurückgegeben;
  • Wenn y ±∞ ist und x +∞ ist, wird ±π/4 zurückgegeben;
  • Wenn x ±0 ist und y negativ ist, wird -π/2 zurückgegeben;
  • Wenn x ±0 ist und y positiv ist, wird +π/2 zurückgegeben;
  • Wenn x -∞ ist und y endlich und positiv ist, wird zurückgegeben;
  • Wenn x -∞ ist und y endlich und negativ ist, wird zurückgegeben;
  • Wenn x +∞ ist und y endlich und positiv ist, wird +0 zurückgegeben;
  • Wenn x +∞ ist und y endlich und negativ ist, wird -0 zurückgegeben;
  • Wenn entweder x NaN oder y NaN ist, wird NaN zurückgegeben.

Hinweise

atan2 ( y, x ) entspricht carg ( x + I * y ) .

POSIX spezifiziert , dass im Fall eines Underflows y / x als Rückgabewert verwendet wird, und falls dies nicht unterstützt wird, ein implementierungsdefinierter Wert zurückgegeben wird, der nicht größer als DBL_MIN , FLT_MIN und LDBL_MIN ist.

Beispiel

#include <math.h>
#include <stdio.h>
int main(void)
{
    // normale Verwendung: Die Vorzeichen der beiden Argumente bestimmen den Quadranten
    // atan2(1,1) = +pi/4, Quadrant I
    printf("(+1,+1) kartesisch ist (%f,%f) polar\n", hypot( 1, 1), atan2( 1, 1));
    // atan2(1, -1) = +3pi/4, Quadrant II
    printf("(+1,-1) kartesisch ist (%f,%f) polar\n", hypot( 1,-1), atan2( 1,-1));
    // atan2(-1,-1) = -3pi/4, Quadrant III
    printf("(-1,-1) kartesisch ist (%f,%f) polar\n", hypot(-1,-1), atan2(-1,-1));
    // atan2(-1,-1) = -pi/4, Quadrant IV
    printf("(-1,+1) kartesisch ist (%f,%f) polar\n", hypot(-1, 1), atan2(-1, 1));
    // spezielle Werte
    printf("atan2(0, 0) = %f atan2(0, -0)=%f\n", atan2(0,0), atan2(0,-0.0));
    printf("atan2(7, 0) = %f atan2(7, -0)=%f\n", atan2(7,0), atan2(7,-0.0));
}

Ausgabe:

(+1,+1) kartesisch ist (1.414214,0.785398) polar
(+1,-1) kartesisch ist (1.414214,2.356194) polar
(-1,-1) kartesisch ist (1.414214,-2.356194) polar
(-1,+1) kartesisch ist (1.414214,-0.785398) polar
atan2(0, 0) = 0.000000 atan2(0, -0)=3.141593
atan2(7, 0) = 1.570796 atan2(7, -0)=1.570796

Referenzen

  • C23-Standard (ISO/IEC 9899:2024):
  • 7.12.4.4 Die atan2-Funktionen (S.: TBD)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S.: TBD)
  • F.10.1.4 Die atan2-Funktionen (S.: TBD)
  • C17-Standard (ISO/IEC 9899:2018):
  • 7.12.4.4 Die atan2-Funktionen (S: 174)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S: 272-273)
  • F.10.1.4 Die atan2-Funktionen (S: 378)
  • C11-Standard (ISO/IEC 9899:2011):
  • 7.12.4.4 Die atan2-Funktionen (S: 239)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S: 373-375)
  • F.10.1.4 Die atan2-Funktionen (S: 519)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.12.4.4 Die atan2-Funktionen (S. 219)
  • 7.22 Typgenerische Mathematik <tgmath.h> (S. 335-337)
  • F.9.1.4 Die atan2-Funktionen (S. 456)
  • C89/C90 Standard (ISO/IEC 9899:1990):
  • 4.5.2.4 Die atan2-Funktion

Siehe auch

(C99) (C99)
berechnet den Arkussinus ( arcsin(x) )
(Funktion)
(C99) (C99)
berechnet den Arkuskosinus ( arccos(x) )
(Funktion)
(C99) (C99)
berechnet den Arkustangens ( arctan(x) )
(Funktion)
(C99) (C99) (C99)
berechnet den Phasenwinkel einer komplexen Zahl
(Funktion)