Skip to content

Latest commit

 

History

History
141 lines (119 loc) · 4.53 KB

File metadata and controls

141 lines (119 loc) · 4.53 KB
title complex<long double> | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-standard-libraries
ms.tgt_pltfrm
ms.topic article
f1_keywords
std::complex<long double>
complex<long double>
std.complex<long double>
dev_langs
C++
helpviewer_keywords
complex<long double> function
ms.assetid 37591991-b385-46e9-b727-d534dbc10432
caps.latest.revision 20
author corob-msft
ms.author corob
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

complex<long double>

Describes an object that stores an ordered pair of objects both of type long double, the first representing the real part of a complex number and the second representing the imaginary part.

Syntax

template <>
class complex<long double> {
public:
    constexpr complex(
    long double _RealVal = 0,
    long double _ImagVal = 0);

complex(
    constexpr complex<long double>& complexNum);
// rest same as template class complex
};

Parameters

_RealVal
The value of type long double for the real part of the complex number being constructed.

_ImagVal
The value of type long double for the imaginary part of the complex number being constructed.

complexNum
The complex number of type double or of type float whose real and imaginary parts are used to initialize a complex number of type long double being constructed.

Return Value

A complex number of type long double.

Remarks

The explicit specialization of the template class complex to a complex class of type long double differs from the template class only in the constructors it defines. The conversion from long double to float is allowed to be implicit, but the conversion from double to long double is required to be explicit. The use of explicit rules out the initiation with type conversion using assignment syntax.

For more information on the template class complex, see complex Class. For a list of members of the template class complex, see .

Example

// complex_comp_ld.cpp  
// compile with: /EHsc  
#include <complex>  
#include <iostream>  
  
int main( )  
{  
   using namespace std;  
   double pi = 3.14159265359;  
  
   // The first constructor specifies real & imaginary parts  
   complex <long double> c1 ( 4.0 , 5.0 );  
   cout << "Specifying initial real & imaginary parts,\n"  
        << " as type float gives c1 = " << c1 << endl;  
  
   // The second constructor initializes values of the real &  
   // imaginary parts using those of complex number of type float  
   complex <float> c2float ( 1.0 , 3.0 );  
   complex <long double> c2longdouble ( c2float );  
   cout << "Implicit conversion from type float to type long double,"  
        << "\n gives c2longdouble = " << c2longdouble << endl;  
  
   // The third constructor initializes values of the real &  
   // imaginary parts using those of a complex number  
   // of type double  
   complex <double> c3double ( 3.0 , 4.0 );  
   complex <long double> c3longdouble ( c3double );  
   cout << "Implicit conversion from type long double to type float,"  
        << "\n gives c3longdouble = " << c3longdouble << endl;  
  
   // The modulus and argument of a complex number can be recovered  
   double absc3 = abs ( c3longdouble );  
   double argc3 = arg ( c3longdouble );  
   cout << "The modulus of c3 is recovered from c3 using: abs ( c3 ) = "  
        << absc3 << endl;  
   cout << "Argument of c3 is recovered from c3 using:\n arg ( c3 ) = "  
        << argc3 << " radians, which is " << argc3 * 180 / pi  
        << " degrees." << endl;  
}  
\* Output:   
Specifying initial real & imaginary parts,  
 as type float gives c1 = (4,5)  
Implicit conversion from type float to type long double,  
 gives c2longdouble = (1,3)  
Implicit conversion from type long double to type float,  
 gives c3longdouble = (3,4)  
The modulus of c3 is recovered from c3 using: abs ( c3 ) = 5  
Argument of c3 is recovered from c3 using:  
 arg ( c3 ) = 0.927295 radians, which is 53.1301 degrees.  
*\  

Requirements

Header: <complex>

Namespace: std

See Also

complex Class
Thread Safety in the C++ Standard Library