1 function FLAG = flag_accuracy_level(i)
2 % FLAG_ACCURACY_LEVEL sets and gets accuracy level
3 % used in SUMSKIPNAN_MEX and COVM_MEX
4 % The error margin of the naive summation is N*eps (N is the number of samples),
5 % the error margin is only 2*eps if Kahan's summation is used [1].
7 % 0: maximum speed [default]
8 % accuracy of double (64bit) with naive summation (error = N*2^-52)
9 % 1: accuracy of extended (80bit) with naive summation (error = N*2^-64)
10 % 2: accuracy of double (64bit) with Kahan summation (error = 2^-52)
11 % 3: accuracy of extended (80bit) with Kahan summation (error = 2^-64)
13 % Please note, level 3 might be equally accurate but slower than 1 or 2 on
14 % some platforms. In order to determine what is good for you, you might want
17 % FLAG = flag_accuracy_level()
19 % flag_accuracy_level(FLAG)
26 % What Every Computer Scientist Should Know About Floating-Point Arithmetic
27 % ACM Computing Surveys, Vol 23, No 1, March 1991.
30 % This program is free software; you can redistribute it and/or modify
31 % it under the terms of the GNU General Public License as published by
32 % the Free Software Foundation; either version 3 of the License, or
33 % (at your option) any later version.
35 % This program is distributed in the hope that it will be useful,
36 % but WITHOUT ANY WARRANTY; without even the implied warranty of
37 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 % GNU General Public License for more details.
40 % You should have received a copy of the GNU General Public License
41 % along with this program; if not, write to the Free Software
42 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
45 % Copyright (C) 2009 by Alois Schloegl <alois.schloegl@gmail.com>
46 % This function is part of the NaN-toolbox
47 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
50 persistent FLAG_ACCURACY_LEVEL;
52 %% if strcmp(version,'3.6'), FLAG_ACCURACY_LEVEL=1; end; %% hack for the use with Freemat3.6
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %% set the default accuracy level for your platform, ACCTEST might help to determine the optimum for your platform.
56 %% If you use Matlab, use level 0 or 2; 1 and 3 are much slower but do not show a better accuracy
57 %% Octave seems to be able to use all 4 levels, were the differences of accuracy between succeeding levels become smaller
58 DEFAULT_ACCURACY_LEVEL = 0; %% maximum speed, accuracy sufficient for most needs.
59 %% DEFAULT_ACCURACY_LEVEL = 2; %% slower, but better accuracy for: AMDx64 Opteron, Phenom, Intel Pentium
60 %% DEFAULT_ACCURACY_LEVEL = 1; %% slower, but better accuracy for: Octave on Intel Atom (no improvement with Matlab, just slower)
61 %% DEFAULT_ACCURACY_LEVEL = 3; %% similar accuracy than 1 or 2 (depending on platform) but even slower.
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 %%% set DEFAULT value of FLAG
66 if isempty(FLAG_ACCURACY_LEVEL),
67 FLAG_ACCURACY_LEVEL = DEFAULT_ACCURACY_LEVEL;
73 FLAG_ACCURACY_LEVEL = double(i);
75 FLAG = FLAG_ACCURACY_LEVEL;