From: Bruno Luong on 19 Feb 2010 04:48 "Christian " <pepico(a)hotmail.com> wrote in message <hlllnf$e59$1(a)fred.mathworks.com>... > "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? As Jan told, Matlab uses floating point control word of 53 bits internal computation. Under windows, you might set the word by something like this (see msdn page for relevant functions): // Set the control word to Matlab preference fpmask = _MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC; fpMatlabstate = _EM_DENORMAL | _EM_INVALID | EM_ZERODIVIDE | _EM_OVERFLOW | _EM_UNDERFLOW | _EM_INEXACT | _IC_AFFINE | _PC_53; // 0x000d001f _clearfp(); // _clearfp before enabling/unmasking a FPU exception _controlfp(fpMatlabstate, fpmask); NOTE: this is undocumented, use at your own risk. Bruno
From: Christian on 19 Feb 2010 05:05 "Christian " <pepico(a)hotmail.com> wrote in message <hljabl$72u$1(a)fred.mathworks.com>... > 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 want to be sure that the precision used in MEX file is the same that that used in Matlab. My results with only Matlab are more satisfactory, so I want to use the same precision in MEX file. Maybe the difference is in the algorithm, but I just want to be sure it is not because of the precision.
From: Jan Simon on 20 Feb 2010 18:52
Dear Christian! > I want to be sure that the precision used in MEX file is the same that that used in Matlab. Then do not call the function _control87 or _controlfp (depends on the compiler?!) but let the Mex interface do this automatically for you. Kind regards, Jan |