Namespaces
Variants

std:: arg (std::complex)

From es.cppreference.net
Definido en el encabezado <complex>
template < class T >
T           arg ( const std:: complex < T > & z ) ;
(1)
Definido en el encabezado <complex>
(A)
float arg ( float f ) ;

double arg ( double f ) ;

long double arg ( long double f ) ;
(hasta C++23)
template < class FloatingPoint >

FloatingPoint

arg ( FloatingPoint f ) ;
(desde C++23)
template < class Integer >
double arg ( Integer i ) ;
(B)
1) Calcula el ángulo de fase (en radianes) del número complejo z .
A,B) Se proporcionan sobrecargas adicionales para todos los tipos enteros y de punto flotante, los cuales son tratados como números complejos con componente imaginario cero.
(since C++11)

Contenidos

Parámetros

z - valor complejo
f - valor de punto flotante
i - valor entero

Valor de retorno

1) std:: atan2 ( std:: imag ( z ) , std:: real ( z ) ) . Si no ocurren errores, este es el ángulo de fase de z en el intervalo [−π; π] .
A) Cero si f es positivo o +0, π si f es negativo o -0, NaN en caso contrario.
B) Cero si i es no negativo, π si es negativo.

Notas

Las sobrecargas adicionales no están obligadas a proporcionarse exactamente como (A,B) . Solo necesitan ser suficientes para garantizar que para su argumento num :

  • Si num tiene un tipo de punto flotante estándar (hasta C++23) T , entonces std :: arg ( num ) tiene el mismo efecto que std :: arg ( std:: complex < T > ( num ) ) .
  • De lo contrario, si num tiene un tipo entero, entonces std :: arg ( num ) tiene el mismo efecto que std :: arg ( std:: complex < double > ( num ) ) .

Ejemplo

#include <complex>
#include <iostream>
int main() 
{
    std::complex<double> z1(1, 0);
    std::complex<double> z2(0, 0);
    std::complex<double> z3(0, 1);
    std::complex<double> z4(-1, 0);
    std::complex<double> z5(-1, -0.0);
    double f = 1.;
    int i = -1;
    std::cout << "phase angle of " << z1 << " is " << std::arg(z1) << '\n'
              << "phase angle of " << z2 << " is " << std::arg(z2) << '\n'
              << "phase angle of " << z3 << " is " << std::arg(z3) << '\n'
              << "phase angle of " << z4 << " is " << std::arg(z4) << '\n'
              << "phase angle of " << z5 << " is " << std::arg(z5) << " "
                 "(the other side of the cut)\n"
              << "phase angle of " << f << " is " << std::arg(f) << '\n'
              << "phase angle of " << i << " is " << std::arg(i) << '\n';
}

Salida:

phase angle of (1,0) is 0
phase angle of (0,0) is 0
phase angle of (0,1) is 1.5708
phase angle of (-1,0) is 3.14159
phase angle of (-1,-0) is -3.14159 (the other side of the cut)
phase angle of 1 is 0
phase angle of -1 is 3.14159

Véase también

devuelve la magnitud de un número complejo
(plantilla de función)
construye un número complejo a partir de magnitud y ángulo de fase
(plantilla de función)
(C++11) (C++11)
arcotangente, usando signos para determinar cuadrantes
(función)
aplica la función std::atan2 a un valarray y un valor
(plantilla de función)