Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is there anything wrong with std::pow?

Reply
Thread Tools

Is there anything wrong with std::pow?

 
 
Peng Yu
Guest
Posts: n/a
 
      09-10-2008
Hi,

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

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:ow(x, 1/.3);
std::cout << y << " " << y * y * y << std::endl;
}
 
Reply With Quote
 
 
 
 
Peng Yu
Guest
Posts: n/a
 
      09-10-2008
On Sep 9, 8:29 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * Peng Yu:
>
>
>
> > Hi,

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

>
> > 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:ow(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
 
Reply With Quote
 
 
 
 
Sjouke Burry
Guest
Posts: n/a
 
      09-10-2008
Peng Yu wrote:
> On Sep 9, 8:29 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
>> * Peng Yu:
>>
>>
>>
>>> Hi,
>>> The output of the following program is
>>> (-27.7128,16) (-9.09495e-12,3276
>>> 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:ow(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.
 
Reply With Quote
 
Peng Yu
Guest
Posts: n/a
 
      09-10-2008
On Sep 9, 9:35 pm, Sjouke Burry <(E-Mail Removed)>
wrote:
> Peng Yu wrote:
> > On Sep 9, 8:29 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> >> * Peng Yu:

>
> >>> Hi,
> >>> The output of the following program is
> >>> (-27.7128,16) (-9.09495e-12,3276
> >>> 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:ow(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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there anything fundamentally wrong with this code? simon.stockton@baesystems.com VHDL 5 04-20-2006 01:09 PM
brut force eigrp over gre working, is there anything wrong? jcharth@hotmail.com Cisco 0 10-05-2005 09:57 PM
Is there anything wrong with the following ? Roubles C Programming 3 05-14-2004 09:22 PM
Is there anything wrong with my insert code? Mano kumar ASP .Net 2 10-17-2003 01:51 PM
Re: Is there anything wrong... rf HTML 1 07-06-2003 11:29 AM



Advertisments