473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Assignment to std::complex number real and imag separately

The page on Bytes.com 'Assignment to std::complex number' obtains a 'no result for assigning the real and imaginary components separately. This page

http://en.cppreference.com/w/cpp/numeric/complex

toward the bottom gives

"For any object z of type complex<T>, reinterpret_cast<T(&)[2]>(z)[0] is the real part of z and reinterpret_cast<T(&)[2]>(z)[1] is the imaginary part of z."

Separate assignment is then, for double type, complex number z

reinterpret_cast<double(&)[2]>(z)[0] = real_assign_number;
reinterpret_cast<double(&)[2]>(z)[1] = imag_assign_number;

Or:

#define REAL64(a) reinterpret_cast<double(&)[2]>(a)[0]
#define IMAG64(a) reinterpret_cast<double(&)[2]>(a)[1]

REAL64(z) = real_assign_number;
IMAG64(z) = imag_assign_number;

Neil
Feb 26 '14 #1
1 1568
weaknessforcats
9,208 Expert Mod 8TB
There are std::complex methods to call to do all of this. These methods and operator overloads do not use casts or macros.
Feb 27 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
8
by: Marc Schellens | last post by:
Does anybody know an easy way to get the atan of a complex number in C++? thanks, marc
4
by: zender | last post by:
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:
21
by: Protoman | last post by:
How do I calculate the log of a number? Don't tell me to use log in cmath; I'm trying to learn complex math in C++. Got any tips/ideas on how to do this? Thanks for the help!!!
77
by: berns | last post by:
Hi All, A coworker and I have been debating the 'correct' expectation of evaluation for the phrase a = b = c. Two different versions of GCC ended up compiling this as b = c; a = b and the other...
1
by: jraul | last post by:
Suppose we have a complex number class and we overload the conversion to double to return the real part. We also overload operator* to do complex multiplication. Consider now: complex a(...);...
7
by: schaefer.mp | last post by:
To compute the absolute value of a negative base raised to a fractional exponent such as: z = (-3)^4.5 you can compute the real and imaginary parts and then convert to the polar form to get...
7
by: huili80 | last post by:
Should complex<T>::real() and imag() return a value or a refernce? What does the standard say about this? I just realized that MSVC2008's implementation returns a value, but in GCC reference is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.