dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: C++ to VB translation

  1. #1
    Join Date
    May 2009
    Posts
    29

    C++ to VB translation

    Good afternoon,

    I'm having some troubles (in the results) to translate the following routine in C++ to VB. It's a routine which messes with complex numbers... So here it is (and how the call is made:

    Code:
    function Solve(const double al, const complex<double> &z, 
                         const double u, complex<double> &zto, double &r)
    {
        const double ex = abs(z);
        const double ex2 = ex*ex;
        const double ex3 = ex2*ex;
    
        double e = (al + (ex - ex3/8)*sin(al) + 0.5 * ex2 * sin(2*al) 
                    + 0.375 * ex3 * sin(3*al));
    
        complex<double> z1 = conj(z);
    
        for (int k = 0; k < 10; k++)
        {
            const complex<double> z2(0, e);
            const complex<double> zteta = exp(z2);
    
            const complex<double> z3 = z1*zteta;
    
            const double dl = al - e + z3.imag();
            r = 1 - z3.real();
            if (fabs(dl) < 1e-12)
            {
                z1 = u * z * z3.imag();
                const complex<double> z2(z1.imag(), -z1.real());
                zto = (-z + zteta + z2)/r;
                return;
            }
            e += dl/r;
        }
        xpWarn("Can't converge\n", __FILE__, __LINE__);
    }
    And it's called like this:

    Code:
        complex<double> z(xk, xh);
        complex<double> zto;
        double r;
    
         Solve(xl, z, u, zto, r);
    Can someone give me an hand please?...

    Kind regards

    JKepler
    Last edited by 2kaud; October 6th, 2018 at 11:21 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,512

    Re: C++ to VB translation

    [When posting code, please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#'']

    Note that

    Code:
    function Solve(const double al, const complex<double> &z, 
                         const double u, complex<double> &zto, double &r)
    should be in c++

    Code:
    void Solve(const double al, const complex<double> &z, 
                         const double u, complex<double> &zto, double &r)
    How far have you got with the conversion to VB6? Can you post the VB6 code you currently have.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.9.4)

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)