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
Post a Comment