C++ POW(X,Y) X negative double and Y negative double, gives nan as result -


i'm trying simple operation, pow(-0.89,-0.67) in c++ 14 code, , gives nan result. when doing same in scilab result -1.08. there way in c++ right result?

i guessing made typo in scilab. must have written

-0.89 ^ -0.67 

which means did -(0.89 ^ -0.67) = -(1.08).

if instead typed

(-0.89) ^ -0.67 

you have gotten answer -0.5504 - 0.9306i. negative root of negative number complex, , pow function in c++ give nan result.

if use std::complex type, correct answer of -0.5504 - 0.9306i:

#include <iostream> #include <complex> #include <cmath>  int main() {     std::complex<double> a(-0.89), b(-0.67);     std::cout << std::pow(a,b) << std::endl;  } 

output:

(-0.550379,-0.93064) 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -