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
Défini dans l'en-tête <math.h>
float atan2f ( float y, float x ) ;
(1) (depuis C99)
double atan2 ( double y, double x ) ;
(2)
long double atan2l ( long double y, long double x ) ;
(3) (depuis C99)
_Decimal32  atan2d32 ( _Decimal32 y, _Decimal32 x ) ;
(4) (depuis C23)
_Decimal64  atan2d64 ( _Decimal64 y, _Decimal64 x ) ;
(5) (depuis C23)
_Decimal128 atan2d128 ( _Decimal128 y, _Decimal128 x ) ;
(6) (depuis C23)
Défini dans l'en-tête <tgmath.h>
#define atan2( y, x )
(7) (depuis C99)
1-6) Calcule l'arc tangente de y / x en utilisant les signes des arguments pour déterminer le quadrant correct.
7) Macro générique de type : Si un argument a le type long double , (3) ( atan2l ) est appelé. Sinon, si un argument a un type entier ou le type double , (2) ( atan2 ) est appelé. Sinon, (1) ( atan2f ) est appelé.

Les fonctions (4-6) sont déclarées si et seulement si l'implémentation prédéfinit __STDC_IEC_60559_DFP__ (c'est-à-dire que l'implémentation prend en charge les nombres à virgule flottante décimale).

(depuis C23)

Table des matières

Paramètres

x, y - valeur en virgule flottante

Valeur de retour

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

Si une erreur de domaine se produit, une valeur définie par l'implémentation est retournée.

Si une erreur de plage se produit en raison d'un dépassement inférieur, le résultat correct (après arrondi) est retourné.

Gestion des erreurs

Les erreurs sont signalées comme spécifié dans math_errhandling .

Une erreur de domaine peut survenir si x et y sont tous deux nuls.

Si l'implémentation prend en charge l'arithmétique à virgule flottante IEEE (IEC 60559) :

  • Si x et y sont tous deux nuls, une erreur de domaine ne se produit pas ;
  • Si x et y sont tous deux nuls, une erreur de plage ne se produit pas non plus ;
  • Si y est nul, une erreur de pôle ne se produit pas ;
  • Si y est ±0 et x est négatif ou -0 , ±π est retourné ;
  • Si y est ±0 et x est positif ou +0 , ±0 est retourné ;
  • Si y est ±∞ et x est fini, ±π/2 est retourné ;
  • Si y est ±∞ et x est -∞ , ±3π/4 est retourné ;
  • Si y est ±∞ et x est +∞ , ±π/4 est retourné ;
  • Si x est ±0 et y est négatif, -π/2 est retourné ;
  • Si x est ±0 et y est positif, +π/2 est retourné ;
  • Si x est -∞ et y est fini et positif, est retourné ;
  • Si x est -∞ et y est fini et négatif, est retourné ;
  • Si x est +∞ et y est fini et positif, +0 est retourné ;
  • Si x est +∞ et y est fini et négatif, -0 est retourné ;
  • Si soit x est NaN ou y est NaN, NaN est retourné.

Notes

atan2 ( y, x ) est équivalent à carg ( x + I * y ) .

POSIX spécifie qu'en cas de dépassement inférieur, y / x est la valeur retournée, et si cela n'est pas pris en charge, une valeur définie par l'implémentation n'excédant pas DBL_MIN , FLT_MIN , et LDBL_MIN est retournée.

Exemple

#include <math.h>
#include <stdio.h>
int main(void)
{
    // usage normal : les signes des deux arguments déterminent le quadrant
    // atan2(1,1) = +pi/4, Quadrant I
    printf("(+1,+1) cartesian is (%f,%f) polar\n", hypot( 1, 1), atan2( 1, 1));
    // atan2(1, -1) = +3pi/4, Quadrant II
    printf("(+1,-1) cartesian is (%f,%f) polar\n", hypot( 1,-1), atan2( 1,-1));
    // atan2(-1,-1) = -3pi/4, Quadrant III
    printf("(-1,-1) cartesian is (%f,%f) polar\n", hypot(-1,-1), atan2(-1,-1));
    // atan2(-1,-1) = -pi/4, Quadrant IV
    printf("(-1,+1) cartesian is (%f,%f) polar\n", hypot(-1, 1), atan2(-1, 1));
    // valeurs spéciales
    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));
}

Sortie :

(+1,+1) cartesian is (1.414214,0.785398) polar
(+1,-1) cartesian is (1.414214,2.356194) polar
(-1,-1) cartesian is (1.414214,-2.356194) polar
(-1,+1) cartesian is (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

Références

  • Norme C23 (ISO/CEI 9899:2024) :
  • 7.12.4.4 Les fonctions atan2 (p: TBD)
  • 7.25 Mathématiques génériques de type <tgmath.h> (p: TBD)
  • F.10.1.4 Les fonctions atan2 (p: TBD)
  • Norme C17 (ISO/CEI 9899:2018) :
  • 7.12.4.4 Les fonctions atan2 (p : 174)
  • 7.25 Mathématiques génériques de type <tgmath.h> (p : 272-273)
  • F.10.1.4 Les fonctions atan2 (p : 378)
  • Norme C11 (ISO/IEC 9899:2011) :
  • 7.12.4.4 Les fonctions atan2 (p: 239)
  • 7.25 Mathématiques génériques <tgmath.h> (p: 373-375)
  • F.10.1.4 Les fonctions atan2 (p: 519)
  • Norme C99 (ISO/CEI 9899:1999) :
  • 7.12.4.4 Les fonctions atan2 (p: 219)
  • 7.22 Mathématiques génériques de type <tgmath.h> (p: 335-337)
  • F.9.1.4 Les fonctions atan2 (p: 456)
  • Norme C89/C90 (ISO/IEC 9899:1990) :
  • 4.5.2.4 Fonction atan2

Voir aussi

(C99) (C99)
calcule l'arc sinus ( arcsin(x) )
(fonction)
(C99) (C99)
calcule l'arc cosinus ( arccos(x) )
(fonction)
(C99) (C99)
calcule l'arc tangente ( arctan(x) )
(fonction)
(C99) (C99) (C99)
calcule l'angle de phase d'un nombre complexe
(fonction)