std::complex<long double> division

Discussion in 'C++' started by Fredy Halter, Jan 24, 2007.

  1. Fredy Halter

    Fredy Halter Guest

    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.
    Fredy Halter, Jan 24, 2007
    #1
    1. Advertising

  2. Fredy Halter

    Ondra Holub Guest

    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
    Ondra Holub, Jan 24, 2007
    #2
    1. Advertising

  3. Fredy Halter

    Rolf Magnus Guest

    Fredy Halter wrote:

    > 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".
    Rolf Magnus, Jan 24, 2007
    #3
  4. Fredy Halter

    Lionel B Guest

    On Wed, 24 Jan 2007 14:56:08 +0100, Fredy Halter wrote:

    > 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>.

    [...]

    --
    Lionel B
    Lionel B, Jan 24, 2007
    #4
  5. Fredy Halter

    Kai-Uwe Bux Guest

    Fredy Halter wrote:

    > 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
    Kai-Uwe Bux, Jan 24, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sydex
    Replies:
    12
    Views:
    6,429
    Victor Bazarov
    Feb 17, 2005
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,161
    Peter Shaggy Haywood
    Sep 20, 2005
  3. Replies:
    94
    Views:
    4,354
    ┬Ča\\/b
    Feb 9, 2007
  4. J.M.
    Replies:
    3
    Views:
    602
    Sarath
    Mar 6, 2007
  5. Replies:
    5
    Views:
    413
    James Kanze
    Jun 27, 2008
Loading...

Share This Page