By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,650 Members | 1,871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,650 IT Pros & Developers. It's quick & easy.

Is there anything wrong with std::pow?

P: n/a
Hi,

The output of the following program is
(-27.7128,16) (-9.09495e-12,32768)

Obviously, y*y*y is not equal to x, even the magnitude is off. I'm
wondering what is wrong here.

Thanks,
Peng

#include <complex>
#include <iostream>

int main () {
std::complex<doublex(2, 2);
std::complex<doubley = std::pow(x, 1/.3);
std::cout << y << " " << y * y * y << std::endl;
}
Sep 10 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sep 9, 8:29 pm, "Alf P. Steinbach" <al...@start.nowrote:
* Peng Yu:
Hi,
The output of the following program is
(-27.7128,16) (-9.09495e-12,32768)
Obviously, y*y*y is not equal to x, even the magnitude is off. I'm
wondering what is wrong here.
Thanks,
Peng
#include <complex>
#include <iostream>
int main () {
std::complex<doublex(2, 2);
std::complex<doubley = std::pow(x, 1/.3);
std::cout << y << " " << y * y * y << std::endl;
}

The second argument to pow.
I don't quite understand what you mean. Would you please be more
specific?

Thanks,
Peng
Sep 10 '08 #2

P: n/a
Peng Yu wrote:
On Sep 9, 8:29 pm, "Alf P. Steinbach" <al...@start.nowrote:
>* Peng Yu:
>>Hi,
The output of the following program is
(-27.7128,16) (-9.09495e-12,32768)
Obviously, y*y*y is not equal to x, even the magnitude is off. I'm
wondering what is wrong here.
Thanks,
Peng
#include <complex>
#include <iostream>
int main () {
std::complex<doublex(2, 2);
std::complex<doubley = std::pow(x, 1/.3);
std::cout << y << " " << y * y * y << std::endl;
}
The second argument to pow.

I don't quite understand what you mean. Would you please be more
specific?

Thanks,
Peng
1/.3 equals 3.333333, perhaps you meant 1./3.
Sep 10 '08 #3

P: n/a
On Sep 9, 9:35 pm, Sjouke Burry <burrynulnulf...@ppllaanneett.nnlll>
wrote:
Peng Yu wrote:
On Sep 9, 8:29 pm, "Alf P. Steinbach" <al...@start.nowrote:
* Peng Yu:
>Hi,
The output of the following program is
(-27.7128,16) (-9.09495e-12,32768)
Obviously, y*y*y is not equal to x, even the magnitude is off. I'm
wondering what is wrong here.
Thanks,
Peng
#include <complex>
#include <iostream>
int main () {
std::complex<doublex(2, 2);
std::complex<doubley = std::pow(x, 1/.3);
std::cout << y << " " << y * y * y << std::endl;
}
The second argument to pow.
I don't quite understand what you mean. Would you please be more
specific?
Thanks,
Peng

1/.3 equals 3.333333, perhaps you meant 1./3.
I'm sorry that I could pinpoint it. Thank you.

Peng
Sep 10 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.