]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/flag_accuracy_level.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / flag_accuracy_level.m
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].    
6 %
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)  
12 %
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
15 %   to run ACCTEST. 
16 %
17 % FLAG = flag_accuracy_level()
18 %       gets current level
19 % flag_accuracy_level(FLAG) 
20 %       sets accuracy level  
21
22 % see also: ACCTEST
23
24 % Reference:
25 % [1] David Goldberg, 
26 %       What Every Computer Scientist Should Know About Floating-Point Arithmetic
27 %       ACM Computing Surveys, Vol 23, No 1, March 1991. 
28
29
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.
34 %
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.
39 %
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
43
44 %       $Id$
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/
48
49
50 persistent FLAG_ACCURACY_LEVEL;
51
52 %% if strcmp(version,'3.6'), FLAG_ACCURACY_LEVEL=1; end;        %% hack for the use with Freemat3.6
53
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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64
65 %%% set DEFAULT value of FLAG
66 if isempty(FLAG_ACCURACY_LEVEL),
67         FLAG_ACCURACY_LEVEL = DEFAULT_ACCURACY_LEVEL;
68 end;
69
70 if nargin>0,
71         if (i>3), i=3; end;
72         if (i<0), i=0; end;
73         FLAG_ACCURACY_LEVEL = double(i); 
74 end;
75 FLAG = FLAG_ACCURACY_LEVEL;
76