How do I make complex int16 numbers in octave?

795 views Asked by At

In Matlab (my version happens to be R2010b) one can convert a complex double into a complex int16 type as so:

>> a = 8.3+4.9j;
>> ai16 = int16(a)
ai16 = 
    8 + 5i
>> whos ai16
Name       Size       Bytes       Class     Attributes
ai16       1x1            4       int16     complex

i.e. ai16 is a complex int16 type (equivalent to C++ complex< short > for example).

Octave (ver 4.0.0) does not like this one bit:

>> ai16 = int16(a)
error: invalid conversion from complex scalar to int16 scalar

I am trying to port some legacy Matlab code to Octave. Does anyone have a suggestion on how to get around this in a painless way? I thought of this:

ai16.real = int16(real(a));
ai16.imag = int16(imag(a));

but that would propagate a lot of pain through out the code base. There are many arrays that have been converted from complex double to complex int16. And these arrays are used in many computations.

0

There are 0 answers