0
Fixed

Errors converting from single complex to mp complex and back

Owen 3 years ago • updated by Pavel Holoborodko 3 years ago 3
I'm getting errors when I try to convert a single-precision complex variable to mp type and back. For example:
>> x = single(1 + i)
x =
1.0000 + 1.0000i
>> x = mp(x)
x =
6.94449606095542138733663817572487e-310 + 5.263544247120890312873936353273975e-315i

Due to the nature of the application I'm working on, I can't get around this by using a string, e.g. mp('1+i'); I have to convert from a single-precision variable. Presently I'm getting around this by casting the variable to double before passing it to mp, e.g. x = mp(double(x)), but I'd like to not have to do that.

In addition, when I try to cast from mp to single, the variable gets cast to a double instead. For example:
>> x = mp('1+i')
x =
1 + 1i
>> x = single(x)
x =
1.0000 + 1.0000i
>> whos
Name Size Bytes Class Attributes
x 1x1 16 double complex

Presently I'm getting around this issue by calling single() twice, e.g. x = single(single(x)), but again, I'd like to not have to do that.

I'm using MATLAB version 8.4.0.150421 (R2014b) and mp version 3.8.5 Build 9059.
Started
Dear Owen,

Both bugs are confirmed and will be fixed in next updates.
Thank you very much for reporting!

Until then, you can try using the following workarounds:

A. For 'mp' to 'single' conversion:

Replace the following line in mp.m (line #1146):
r =  mpimpl(9000,x);
with
r = single(mpimpl(9000,x));
B. For 'single' to 'mp':

Please insert this code after #667 line in mp.m:
           if nargin == 1
            if isa(x,'single'), x = double(x); end;
           end;
These issues have been already fixed in Windows version - you can download it from our website the usual way.
Updates for GNU Linux & Mac OSX follow (I know you probably use the GNU Linux version).
Fixed
The issues have been fixed on all platforms.