[petsc-users] sqrt for a PetscScalar

Barry Smith bsmith at mcs.anl.gov
Wed Apr 7 11:28:52 CDT 2010


> no match for ‘operator/’ in ‘1 / std::sqrt [with
                                         ^^^^

     It is complaining about the operator / not the sqrt. Try 1.0 /  
sqrt(xTMx) instead. Sometimes the complex class is real braindead  
about casting from ints.

     Barry


On Apr 7, 2010, at 5:47 AM, Umut Tabak wrote:

> Dear all,
>
> I am getting a compilation error from the sqrt(cmath header)  
> function with PETSc 3.1, I configured PETSc with complex scalar type  
> so I am suspecting that this is the source of the problem.
>
> Is there a simple workaround for this? And Is there an sqrt function  
> for a 'PetscScalar', I could not find that in the documentation?
>
> PetscScalar xTMx;
> ...
> VecScale(x, 1/sqrt(xTMx));
>
> /home/utabak/thesis/C++/c++Projects/workDirectory/trunk/src/ 
> evpSolver1.cc:502: error: no match for ‘operator/’ in ‘1 / std::sqrt  
> [with _Tp = double](((const std::complex<double>&)((const  
> std::complex<double>*)(& xTMx))))’
> /usr/include/c++/4.3/bits/stl_pair.h: In constructor ‘std::pair<_T1,  
> _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 =  
> std::complex<double>, _U2 = int, _T1 = const double, _T2 = int]’:
>
>
> Best regards,
> Umut



More information about the petsc-users mailing list