From help-request at octave dot org Fri Feb 18 14:01:22 2005 Subject: Re: C++ using Octave headers, mkoctfile From: Geraint Paul Bevan To: sct at ucsd dot edu CC: help at octave dot org Date: Fri, 18 Feb 2005 20:18:04 +0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Steve C. Thompson wrote: | You are absolutely correct. But this code snippet was to serve as an | example only. Let me simplify the question: | | How do I return a complex number from a custom .oct file? | Complex is really complex, i.e. the standard C++ complex template with type double as the data, as can be seen from this line in octave/oct-cmplx.h: typedef std::complex Complex; You form complex numbers using a constructor of the form: Complex (double realpart, double imagpart) oct-cmplx.h then goes on to define functions using these Complex data types. $ cat cplx.cc && mkoctfile cplx.cc && echo [a,b] = cplx | octave -q #include DEFUN_DLD (cplx, args, , "simple Complex example") { ~ static octave_value_list retval; ~ Complex z (0,1); // real part = 0, imag part = 1 ~ retval(0) = z; ~ retval(1) = exp(z); ~ return retval; } a = 0 + 1i b = 0.54030 + 0.84147i - -- Geraint Bevan http://homepage.ntlworld.com/geraint.bevan -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iEYEARECAAYFAkIWTXsACgkQcXV3N50QmNP+XwCfb6YoRNAxugcrxn4BdfTy4EU/ WskAn1fKArpwFQGlGaHkpJAsypi3rFNP =jZHp -----END PGP SIGNATURE----- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------