From: Jan Simon on
Dear Oliver!

> I understand why the results might be different. MATLAB follows IEEE floating point arithmetic rules, so uses a 53-bit mantissa in calculations. However, most modern CPUs use a 64-bit mantissa internally when doing the same calculations, which the compiled mex code will make use of. Therefore these results should be more accurate. Are you MATLAB's results are the more accurate of the two?
> Oliver

Without setting it manually with _control87 or in Matlab with
systemdependent('setprecision', 64)
the calculations happen with 53 bit in Matlab and in the Mex file.

But be aware that calculations need not be more accurate with 64 bit! E.g. Kahan's method for compensating the errors in the sum of floating point numbers fails when the intermediate values are computed with the higher precision, and finally the result is worse.

Kind regards, Jan
From: Christian on
"Oliver Woodford" <o.j.woodford.98(a)cantab.net> wrote in message <hljkad$se6$1(a)fred.mathworks.com>...
> "Christian " wrote:
> > Hello all
> >
> > I am trying to model a communication system in Matlab. Because of time computation, I have moved a part of the code into some mex files. When running the program with just Matlab the results are more satisfactory than the results when Matlab/MEX is used. My only explanation for this is a difference of precision in the computations involved The code programmed in these MEX files are computationally costful, complex data is involved and require a high degree of precision.
> >
> > Since the mxArray are double precision, my question is: how can I use mxArray structures in MEX files with long double precision? The pointers at these mxArray have been declared as long double *, but I do not see any change and the results are still different from those obtained when only Matlab is used.
> >
> > Thanks in advance
>
> I understand why the results might be different. MATLAB follows IEEE floating point arithmetic rules, so uses a 53-bit mantissa in calculations. However, most modern CPUs use a 64-bit mantissa internally when doing the same calculations, which the compiled mex code will make use of. Therefore these results should be more accurate. Are you MATLAB's results are the more accurate of the two?
> Oliver

Well, I could not say which one is more accurate. I am trying a technique to detect the information signal sent, and using only matlab the number of errors is smaller. It would be more convenient for me that Matlab used a higher precision than mex.

The algorithm involves complex operations, the results depends on previous computations,...a smaller difference in the precision computation may explain the difference. Why Matlab does obtain a smaller number of errors? Strange
From: Oliver Woodford on
"Jan Simon" wrote:
> Without setting it manually with _control87 or in Matlab with
> systemdependent('setprecision', 64)
> the calculations happen with 53 bit in Matlab and in the Mex file.

Interesting. Thanks, Jan!
From: Jan Simon on
Typo:
> > systemdependent('setprecision', 64)
system_dependent('setprecision', 64)

Jan
From: Christian on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hljnp1$hkd$1(a)fred.mathworks.com>...
> Typo:
> > > systemdependent('setprecision', 64)
> system_dependent('setprecision', 64)
>
> Jan

May you tell me please which steps I should take to use the same precision in MEX than that used in matlab?