Professional Web Applications Themes

basic c++ app in Xcode : complex number functions - Mac Programming

hi, i am trying with no success to run some scientific code written in c++ with Xcode (macos 10.3). my problem is that the compiler does not accept mathematical functions with complex numbers although i included the complex.h header. here is a short example of program that fails to build : #include <iostream> #include <complex.h> int main (int argc, const char * argv[]) { // insert code here... _Complex double aa,bb=1.0+1.0i; aa=sqrt(bb); std::cout << "Hello, World!\n"; return 0; } the build error is "cannot convert `__complex__ double' to `double' for argument `1' to `double sqrt(double)' can anyone solve my problem? ...

  1. #1

    Default basic c++ app in Xcode : complex number functions

    hi,

    i am trying with no success to run some scientific code written in c++
    with Xcode (macos 10.3).
    my problem is that the compiler does not accept mathematical functions
    with complex numbers although i included the complex.h header.

    here is a short example of program that fails to build :

    #include <iostream>
    #include <complex.h>

    int main (int argc, const char * argv[]) {
    // insert code here...
    _Complex double aa,bb=1.0+1.0i;
    aa=sqrt(bb);
    std::cout << "Hello, World!\n";
    return 0;
    }


    the build error is "cannot convert `__complex__ double' to `double' for
    argument `1' to `double sqrt(double)'

    can anyone solve my problem?

    thanks,
    Jeff

    fr

    --
    J.F. Bobo
    CNRS researcher
    Toulouse, France
    Jean-François Guest

  2. #2

    Default Re: basic c++ app in Xcode : complex number functions

    In article <free.fr>,
    Jean-François Bobo <fr> wrote:
     

    A couple of guesses:

    - as far as I know, _Complex is not a C++ type. A quick Google
    shows that it porbably is a C99 type
    The (IMO) correct C++ type is std::complex
    - shouldn't you use "std::sqrt"?

    Reinder
    Reinder Guest

  3. #3

    Default Re: basic c++ app in Xcode : complex number functions

    On Wed, 24 Dec 2003 14:40:48 +0100, Jean-François Bobo wrote: 
     
     
     
     

     

    Here is a version that works. Note that "std::complex" is a template
    type in C++ and the header name is <complex>, not <complex.h>. I
    compiled this on the command line, but it should work in XCode:

    #include <iostream>
    #include <complex>

    int main (int argc, const char * argv[]) {
    std::complex<double> aa, bb(1.0,1.0);
    aa=sqrt(bb);
    std::cout << "The square root of " << bb << " is " << aa << ".\n";
    }

    This program prints:
    The square root of (1,1) is (1.09868,0.45509).



    --
    Dave Seaman
    Judge Yohn's mistakes revealed in Mumia Abu-Jamal ruling.
    <http://www.commoncouragepress.com/index.cfm?action=book&bookid=228>
    Dave Guest

  4. #4

    Default Re: basic c++ app in Xcode : complex number functions

    A few suggestions:

    The c++ stdlib is pretty lackluster when it comes to scientific
    programming. If you really care about the speed of your programs, you
    might want to write your own complex class. I have one that I use if
    you don't want to write your own let me know.

    Use the following command above said program to avoid having to type
    std:: in front of every standard library function:
    using namespace std;

    Good luck.

    Joel

    Dave Seaman <such.host> wrote in message news:<bsccah$2e7$cc.purdue.edu>... 




    >

    >
    > Here is a version that works. Note that "std::complex" is a template
    > type in C++ and the header name is <complex>, not <complex.h>. I
    > compiled this on the command line, but it should work in XCode:
    >
    > #include <iostream>
    > #include <complex>
    >
    > int main (int argc, const char * argv[]) {
    > std::complex<double> aa, bb(1.0,1.0);
    > aa=sqrt(bb);
    > std::cout << "The square root of " << bb << " is " << aa << ".\n";
    > }
    >
    > This program prints:
    > The square root of (1,1) is (1.09868,0.45509).[/ref]
    Jack Guest

Similar Threads

  1. Double number of calls when Basic Authentication?
    By Joe H in forum ASP.NET Security
    Replies: 4
    Last Post: May 28th, 01:24 AM
  2. style of functions with complex arguments
    By Robin Sheat in forum PERL Beginners
    Replies: 3
    Last Post: January 30th, 03:07 PM
  3. Dark basic pro VS blitz basic 3D VS 3d game studio VS shockwave VS jamajic
    By kavelle webforumsuser@macromedia.com in forum Macromedia Director 3D
    Replies: 1
    Last Post: January 29th, 09:53 AM
  4. #10743 [Com]: class functions & PHP core functions inconsistently clash ;)
    By destes at ix dot netcom dot com in forum PHP Development
    Replies: 0
    Last Post: August 11th, 09:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139