Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Assignment to std::complex number

Reply
Thread Tools

Assignment to std::complex number

 
 
zender@uci.edu
Guest
Posts: n/a
 
      01-01-2005
Hi,

Is it possible to a value separately to the real or imaginary
part of a complex number?

Any help appreciated,
Charlie

The following code shows that .real() and .imag() are not lvalues:

#include <iostream>
#include <complex>
int main()
{
std::complex<double> scalar;
scalar.real()=0.0;
}

zender@ashes:~/c++$ g++ -Wall -g -I${HOME}/include -o tst tst.cc
tst.cc: In function `int main()':
tst.cc:17: error: non-lvalue in assignment

 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      01-02-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hi,
>
> Is it possible to a value separately to the real or imaginary
> part of a complex number?


I don't think so.

>
> Any help appreciated,
> Charlie
>
> The following code shows that .real() and .imag() are not lvalues:


True. They return by value, not by reference.

>
> #include <iostream>
> #include <complex>
> int main()
> {
> std::complex<double> scalar;
> scalar.real()=0.0;


scalar = std::complex<double>(0, scalar.imag());

> }


-Mike


 
Reply With Quote
 
 
 
 
Jonathan Turkanis
Guest
Posts: n/a
 
      01-02-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> Is it possible to a value separately to the real or imaginary
> part of a complex number?


No, but there is support for adding this feature. See
http://www.open-std.org/jtc1/sc22/wg...004/n1589.html.

Jonathan


 
Reply With Quote
 
Charlie Zender
Guest
Posts: n/a
 
      01-02-2005
Thanks for the info!
Making real and imaginary component public and separatly assignable
would simplify many physics codes.

Charlie

 
Reply With Quote
 
John Carson
Guest
Posts: n/a
 
      01-02-2005
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com
> Hi,
>
> Is it possible to a value separately to the real or imaginary
> part of a complex number?
>
> Any help appreciated,
> Charlie
>
> The following code shows that .real() and .imag() are not lvalues:
>
> #include <iostream>
> #include <complex>
> int main()
> {
> std::complex<double> scalar;
> scalar.real()=0.0;
> }
>


For what it is worth VC++.Net offers the following "set function" as a
non-standard extension (presumably courtesy of the Dinkumware library that
it uses):

#include <iostream>
#include <complex>
int main()
{
std::complex<double> scalar;
scalar.real(0.0);
}


--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

 
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
How do fix: "Wrong number of arguments" / "invalid propert assignment"/ "Invalid argument" Java Guy Java 1 10-15-2006 08:31 PM
Assignment operator self-assignment check Chris C++ 34 09-26-2006 04:26 AM
Augument assignment versus regular assignment nagy Python 36 07-20-2006 07:24 PM
OT: Number Nine, Number Nine, Number Nine FrisbeeŽ MCSE 37 09-26-2005 04:06 PM
Number Assignment and Number Portability Brian Young VOIP 2 05-09-2004 03:11 PM



Advertisments