Return a complex variable help

I am trying to return a complex varaible, to pass two pieces of data from one function to another.
I thought I understood this, but I am having trouble somehow.
The real part works just fine, but the imaginary part is not being returned.
Any help with the code below would be appreciated.
FYI - I am using Igor Version 6.3.1.2 on Windows 7, maybe a bug?

#pragma rtGlobals=3     // Use modern global access method and strict wave access.

Function tester(sam, bill)
    Variable sam
    Variable bill
    Variable/C dummy = cmplx(sam + 2, bill + 3)
    Return dummy
End

Function Check()
    Make/C/O/N = 100 wave0
    Variable i
    for(i = 0; i < 100; i += 1)
        wave0[i] = tester(i, i*2)
    endfor
End
To return a complex variable you need to declare the function as such, like this:
Function/C Tester(...)

If you wish to pass several pieces of data at the same time, you can always use globally available waves. Another way, somehat akin to passing a complex number, is to use a function that returns a wave reference. Here is an example extending your case to three variables:
Function/WAVE tester3(sam, bill, alex)
    variable sam, bill, alex
   
    Make/O/N=3 wOut = { sam + 2,  bill + 3, alex + 4 }
    Return wOut
end

Function Check3()
    Make/O/N=(100,3)  wave1
    Variable i
    for(i=1; i<100; i+=1)
        wave wout = tester3(i, i*2, i*3)
        wave1[i][0] = wout[0]; wave1[i][1] = wout[1]; wave1[i][2] = wout[2]
    endfor
End
s.r.chinn wrote:
If you wish to pass several pieces of data at the same time, you can always use globally available waves...

Thanks, this gets around having to mess with complex variables all together.
This whole thread reminds us that the best way to deal with this is to add the ability to return multiple objects from a function. This is much more convenient (and adopted by many of Igor's competitors).

The typical syntax is something like {out_object1,out_object2, ...} = funcname(inobject1,inobject2,...)
where out_object1, etc. could be anything (variable, wave, string, structure,...) and {...} is a list

This gets around the whole dance of using complex numbers (which only works for 2 numerical variables), which is a bad kluge (only works in 1 case, uses complex numbers for things that have nothing to do with complex numbers, etc.). Using global variables is also a bad solution, as it is far too easy to lose track of such objects, to overwrite them inappropriately, etc.

Pass by reference is a slightly better method but still far inferior to the straightforward solution proposed above. The issues are that there is no distinction in the syntax of calling, etc. between the input and output objects, making it less clear and more prone to programming slip ups.

The proposed solution also gets around the problem of creating programmatic names (extracting the NameofWave, creating a wave using $(), then creating a wave reference) and
leads to much cleaner code. In other words, you could write

{w1,w2} = funcname(w)

Function funcname(w)
     wave w
     return {w+1,w+2}   // example operation
End


rather than

funcname(w)
wave w1,w2    // see how these "pop out of the blue"

Function funcname(w)
     wave w
     string ws=Nameofwave(w), ws1,ws2
     ws1 = $ws+"1"
     ws2 = $ws+"2"
     duplicate /o w, $ws1, $ws2
     wave wtemp1=$ws1, wtemp2=$ws2
     wtemp1 = w+1 // example operations
     wtemp2 = w+2
End


Sorry for the rant, but this is one area of Igor that badly needs improvement.