std::complex<long double> division

F

Fredy Halter

the following code is not working:

std::complex<long double> x(1.,1.);
std::complex<long double> result(0.,0.);

result = 1./x;

std::cout << "x = " << x << std::endl;
std::cout << "r = " << result << std::endl;


with std::complex<double> it works. anyone knows how to get rid of this?
i need long double for my calculations. thx.
 
O

Ondra Holub

Fredy Halter napsal:
the following code is not working:

std::complex<long double> x(1.,1.);
std::complex<long double> result(0.,0.);

result = 1./x;

std::cout << "x = " << x << std::endl;
std::cout << "r = " << result << std::endl;


with std::complex<double> it works. anyone knows how to get rid of this?
i need long double for my calculations. thx.

Write it this way:
result = 1.L / x;

1. is double, 1.L is long double
 
R

Rolf Magnus

Fredy said:
the following code is not working:

std::complex<long double> x(1.,1.);
std::complex<long double> result(0.,0.);

result = 1./x;

std::cout << "x = " << x << std::endl;
std::cout << "r = " << result << std::endl;


with std::complex<double> it works. anyone knows how to get rid of this?

Get rid of what? Define "not working".
 
L

Lionel B

the following code is not working:

(In future please define "not working" and supply complete compilable code)
std::complex<long double> x(1.,1.);
std::complex<long double> result(0.,0.);

result = 1./x;

result = std::complex<long double>(1.)/x;

There is no operator / (at least not on my system) that takes a lhs of
type double and a rhs of type std::complex<long double>.

[...]
 
K

Kai-Uwe Bux

Fredy said:
the following code is not working:

std::complex<long double> x(1.,1.);
std::complex<long double> result(0.,0.);

result = 1./x;

result = 1.0L / x;
std::cout << "x = " << x << std::endl;
std::cout << "r = " << result << std::endl;


with std::complex<double> it works.

The type of the floating point literal needs to match the type for the
complex.

[snip]


Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top