C++ complex norm


The C++ <complex> ‘abs’ function compute the squared magnitude of the complex number.The declaration of the function is given below.

template< class T> T norm(const complex<T>& x);

Parameters:
x -The complex number whose squared magnitude is to be computed.

Return type
T -The squared of the magnitude of ‘x’.

Some points to note:

i) The norm(x) is same as ‘abs(x)*abs(x)‘ .

Link :C++ complex abs function

Code example

complex< double > c1(3 , 4);

cout<< norm( c1 ) << endl
<< abs( c1 ) * abs(c1) ;

Output ,

91.1125
91.1125