[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Is there anything wrong with std::pow?

Peng Yu

9/10/2008 1:19:00 AM

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<double> x(2, 2);
std::complex<double> y = std::pow(x, 1/.3);
std::cout << y << " " << y * y * y << std::endl;
}
4 Answers

Alf P. Steinbach

9/10/2008 1:30:00 AM

0

* 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<double> x(2, 2);
> std::complex<double> y = std::pow(x, 1/.3);
> std::cout << y << " " << y * y * y << std::endl;
> }

The second argument to pow.

Cheers & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Peng Yu

9/10/2008 2:06:00 AM

0

On Sep 9, 8:29 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> * 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<double> x(2, 2);
> > std::complex<double> y = 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

Sjouke Burry

9/10/2008 2:35:00 AM

0

Peng Yu wrote:
> On Sep 9, 8:29 pm, "Alf P. Steinbach" <al...@start.no> wrote:
>> * 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<double> x(2, 2);
>>> std::complex<double> y = 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.

Peng Yu

9/10/2008 3:01:00 AM

0

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.no> wrote:
> >> * 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<double> x(2, 2);
> >>> std::complex<double> y = 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