1 ## Copyright (C) 2003 Motorola Inc
2 ## Copyright (C) 2003 David Bateman
4 ## This program is free software; you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2 of the License, or
7 ## (at your option) any later version.
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
18 ## @deftypefn {Function File} {} fixedpoint ('help')
19 ## @deftypefnx {Function File} {} fixedpoint ('info')
20 ## @deftypefnx {Function File} {} fixedpoint ('info', @var{mod})
21 ## @deftypefnx {Function File} {} fixedpoint ('test')
22 ## @deftypefnx {Function File} {} fixedpoint ('test', @var{mod})
24 ## Manual and test code for the Octave Fixed Point toolbox. There are
25 ## 5 possible ways to call this function.
28 ## @item fixedpoint ('help')
29 ## Display this help message. Called with no arguments, this function also
30 ## displays this help message
31 ## @item fixedpoint ('info')
32 ## Open the Fixed Point toolbox manual
33 ## @item fixedpoint ('info', @var{mod})
34 ## Open the Fixed Point toolbox manual at the section specified by
36 ## @item fixedpoint ('test')
37 ## Run all of the test code for the Fixed Point toolbox.
41 ## Valid values for the varibale @var{mod} are
45 ## The section describing the use of the fixed point toolbox within Octave
46 ## @item 'programming'
47 ## The section descrining how to use the fixed-point type with oct-files
49 ## The section describing an in-depth example of the use of the fixed-point
52 ## The refernce section of all of the specific fixed point operators and
56 ## Please note that this function file should be used as an example of the
57 ## use of this toolbox.
60 function retval = fixedpoint(typ, tests)
69 infofile = [fileparts(mfilename('fullpath')),'/doc.info'];
76 vers = sscanf(OCTAVE_VERSION, "%i.%i.%i");
78 if strcmp(tests,"all")
80 elseif strcmp(tests,"basics")
82 elseif strcmp(tests,"programming")
83 nodename = "Programming";
84 elseif strcmp(tests,"example")
86 elseif strcmp(tests,"reference")
87 nodename = "Function Reference";
89 error ("fixedpoint: unrecognized section");
92 if (strcmp(typ,"help"))
94 elseif (strcmp(typ,"info"))
96 if (!isempty(char (strsplit (path, ":"))))
97 infopaths =[infopaths; char (strsplit (path, ":"))];
99 if (!isempty(char (strsplit (DEFAULT_LOADPATH, ":"))))
100 infopaths =[infopaths; char (strsplit (DEFAULT_LOADPATH, ":"))];
102 for i=1:size(infopaths,1)
103 infopath = deblank(infopaths(i,:));
104 len = length(infopath);
106 if (len > 1 && strcmp(infopath([len-1, len]),"//"))
107 [status, showfile] = system(["find '", infopath(1:len-1), ...
108 "' -name ", infofile]);
110 [status, showfile] = system(["find '", infopath, "' -name ", ...
111 infofile, " -maxdepth 1"]);
113 if (length(showfile))
118 if (!exist("showfile") || !length(showfile))
119 error("fixedpoint: info file not found");
121 if (showfile(length(showfile)) == "\n")
122 showfile = showfile(1:length(showfile)-1);
125 if (exist("INFO_PROGAM"))
126 [testret, testout] = system(["'", INFO_PROGRAM, "' --version"]);
128 error("fixedpoint: info command not found");
130 system(["'", INFO_PROGRAM, "' --file '", showfile, "' --node '", ...
134 [testret, testout] = system("info --version");
136 error("fixedpoint: info command not found");
138 system(["info --file '", showfile, "' --node '", nodename, "'"]);
141 elseif (strcmp(typ,"test"))
142 pso = page_screen_output();
144 page_screen_output(0);
147 fprintf("\n<< Fixed Point Load Type >>\n");
149 ## Load a fixed point variable to start things off
152 if (!exist("fixed_point_warn_overflow") || !exist("fixed_point_debug") ||
153 !exist("fixed_point_count_operations") ||
154 !exist("fixed_point_version"))
155 error("Can not find fixed point type")
158 fprintf(" Found Fixed Point Toolbox (version %s)\n",
159 fixed_point_version);
161 fprintf("\n<< Fixed Point Creation >>\n");
162 fprintf(" Scalar Creation: ");
164 if (zero.x != 0.) || (zero.int != is) || (zero.dec != ds)
167 if (!isscalar(zero) || !ismatrix(zero) || !isfixed(zero) ||
171 if any(zero) || all(zero)
174 if (size(zero) != [1,1]) || (length(zero) != 1)
177 zero.int = zero.int+1;
178 zero.dec = zero.dec+1;
179 if (zero.x != 0.) || (zero.int != is+1) || (zero.dec != ds+1)
182 empty = fixed(is,ds,[]);
183 if (isscalar(empty) || ismatrix(empty) || !isfixed(empty) ||
184 isvector(empty) || !isempty(empty) || isempty(zero))
188 x = (vals(2)-vals(1))*rand(1,1)+vals(1);
189 a = fixed(is, ds, x);
190 if (abs(a.x - x) > feps) || (a.sign != sign(a.x)) || !isfixed(a)
195 fprintf(" Matrix Creation: ");
196 zero = fixed(is,ds,zeros(n,n));
198 if (any(any(zero.x)) || any(any(zero.int != is)) ||
199 any(any(zero.dec != ds)))
202 if (isscalar(zero) || !ismatrix(zero) || !isfixed(zero) ||
206 if any(any(zero)) || all(all(zero))
209 if (size(zero) != [n,n])
212 zero.int = zero.int+1;
213 zero.dec = zero.dec+1;
214 if (any(any(zero.x)) || any(any(zero.int != is+1)) ||
215 any(any(zero.dec != ds+1)))
219 x = (vals(2)-vals(1))*rand(n,n)+vals(1);
220 a = fixed(is, ds, x);
221 if (any(any(abs(a.x - x) > feps)) || any(any(a.sign != sign(a.x)))
226 b = freshape(a,n*n,1);
227 if (isscalar(b) || !ismatrix(b) || !isfixed(b) || !isvector(b))
233 zero = fixed(is,ds,0);
234 vec = fixed(is,ds,[1:n]);
236 if (size(a,1) != n || size(a,2) != n)
241 if ((i == j) && (a(i,j) != vec(i)))
243 elseif ((i != j) && (a(i,j) != zero))
249 if (length(vec) != n)
253 if (a(i,i) != vec(i))
258 fprintf(" Complex Scalar Creation: ");
259 onei = fixed(is*(1+1i),ds*(1+1i),1+1i);
260 if ((onei.x != 1+1i) || (onei.int != is*(1+1i)) ||
261 (onei.dec != ds*(1+1i)))
264 if (!isscalar(onei) || !ismatrix(onei) || !isfixed(onei) ||
265 !isvector(onei) || !iscomplex(onei))
268 if !any(onei) || !all(onei)
271 if (size(onei) != [1,1]) || (length(onei) != 1)
274 onei.int = onei.int+1;
275 onei.dec = onei.dec+1;
276 if ((onei.x != 1+1i) || (onei.int != is*(1+1i)+1) ||
277 (onei.dec != ds*(1+1i)+1))
280 empty = fixed(is*(1+1i),ds*(1+1i),[]);
281 if (isscalar(empty) || ismatrix(empty) || !isfixed(empty) ||
282 isvector(empty) || !isempty(empty) || isempty(onei) ||
284 ## Not complex, since its type is narrowed!!
289 x = (vals(2)-vals(1))*rand(1,1)+vals(1) + ...
290 1i * (vals(2)-vals(1))*rand(1,1)+vals(1);
291 a = fixed(is, ds, x);
292 if ((abs(real(a.x) - real(x)) > feps) ||
293 (abs(imag(a.x) - imag(x)) > feps) || !isfixed(a))
298 fprintf(" Complex Matrix Creation: ");
299 onei = fixed(is*(1+1i),ds*(1+1i),ones(n,n)*(1+1i));
301 if (any(any(onei.x != 1+1i)) || any(any(onei.int != is*(1+1i))) ||
302 any(any(onei.dec != ds*(1+1i))))
305 if (isscalar(onei) || !ismatrix(onei) || !isfixed(onei) ||
306 isvector(onei) || !iscomplex(onei))
309 if !any(any(onei)) || !all(all(onei))
312 if (size(onei) != [n,n])
315 onei.int = onei.int+1;
316 onei.dec = onei.dec+1;
317 if (any(any(onei.x != 1+1i)) || any(any(onei.int != is*(1+1i)+1)) ||
318 any(any(onei.dec != ds*(1+1i)+1)))
322 x = (vals(2)-vals(1))*rand(n,n)+vals(1) + ...
323 1i * (vals(2)-vals(1))*rand(n,n)+vals(1);
324 a = fixed(is, ds, x);
325 if (any(any(abs(real(a.x) - real(x)) > feps)) ||
326 any(any(abs(imag(a.x) - imag(x)) > feps)) || !isfixed(a))
330 b = freshape(a,n*n,1);
331 if (isscalar(b) || !ismatrix(b) || !isfixed(b) || !isvector(b))
337 zero = fixed(is,ds,0);
338 vec = fixed(is*(1+1i),ds*(1+1i),[1:n]*(1+1i));
340 if (size(a,1) != n || size(a,2) != n)
345 if ((i == j) && (a(i,j) != vec(i)))
347 elseif ((i != j) && (a(i,j) != zero))
353 if (length(vec) != n)
357 if (a(i,i) != vec(i))
362 fprintf(" Indexed Access of Scalars: ");
364 a(2) = fixed(is,ds,2);
365 if (!isvector(a) || !isfixed(a))
369 a(2) = fixed(is,ds,1i);
370 if (!isvector(a) || !isfixed(a) || !iscomplex(a))
374 a(1).dec = a(1).dec + 1;
379 a(2) = fixed(is,ds,2*1i);
380 if (!isvector(a) || !isfixed(a) || !iscomplex(a))
384 a(1).dec = a(1).dec + 1;
385 if (a.dec != ds*(1+1i)+1)
389 fprintf(" Indexed Access of Matrices: ");
390 x = (vals(2)-vals(1))*rand(n,n)+vals(1);
391 a = fixed(is, ds, x);
392 if (any(any(abs(a(1,:).x - x(1,:)) > feps)) || !isfixed(a))
395 a(1,:).dec = a(1,:).dec + 1;
396 if (a(1,:).dec != ds+1)
399 if (a(2,:).dec != ds)
402 a(1,1) = fixed(is,ds,1i);
403 if (!ismatrix(a) || !isfixed(a) || !iscomplex(a))
406 x = ((vals(2)-vals(1))*rand(n,n)+vals(1) +
407 ((vals(2)-vals(1))*rand(n,n)+vals(1)) * 1i);
408 a = fixed(is, ds, x);
409 if (any(any(abs(real(a(1,:).x) - real(x(1,:))) > feps)) ||
410 any(any(abs(imag(a(1,:).x) - imag(x(1,:))) > feps)) ||
414 a(1,:).dec = a(1,:).dec + 1;
415 if (a(1,:).dec != ds*(1+1i)+1)
418 if (a(2,:).dec != ds*(1+1i))
423 fprintf("\n<< Fixed Point Operators >>\n");
425 fprintf(" Logical Operators: ");
426 if (_fixedpoint_test_bool_operator("==",is,ds,n) ||
427 _fixedpoint_test_bool_operator("!=",is,ds,n) ||
428 _fixedpoint_test_bool_operator(">",is,ds,n) ||
429 _fixedpoint_test_bool_operator("<",is,ds,n) ||
430 _fixedpoint_test_bool_operator(">=",is,ds,n) ||
431 _fixedpoint_test_bool_operator("<=",is,ds,n))
437 fprintf(" Unary Operators: ");
438 if (_fixedpoint_test_unary_operator("-",is,ds,n,1) ||
439 _fixedpoint_test_unary_operator("+",is,ds,n,1) ||
440 _fixedpoint_test_unary_operator("'",is,ds,n,0) ||
441 _fixedpoint_test_unary_operator(".'",is,ds,n,0))
446 # This has special meaning for fixed point. Whats the test !!!!
447 # Is the damn operator even correct !!
450 fprintf(" Arithmetic Operators: ");
451 if (_fixedpoint_test_operator("-",is,ds,n,1,1,1) ||
452 _fixedpoint_test_operator("+",is,ds,n,1,1,1) ||
453 _fixedpoint_test_operator(".*",is,ds,n,1,1,1) ||
454 _fixedpoint_test_operator("*",is,ds,n,1,1,1) ||
455 _fixedpoint_test_operator("./",is,ds,n,0,1,1) ||
457 ## Bug in octave 2.1.50 and earlier for el_ldiv in op-cs-s.cc.
458 ((vers(1) > 2 || (vers(1) >= 2 && vers(2) > 1) ||
459 (vers(1) >= 2 && vers(2) >= 1 && vers(3) > 50)) &&
460 _fixedpoint_test_operator(".\\",is,ds,n,0,1,1)) ||
462 ## Rounding errors in complex pow functions make these fail
463 ## _fixedpoint_test_operator(".**",is,ds,n,0,1,1) ||
464 ## _fixedpoint_test_operator(".^",is,ds,n,0,1,1)
466 ## Can't do "matrix-by-matrix", as well as above problem
467 ## _fixedpoint_test_operator("**",is,ds,n,0,1,0) ||
468 ## _fixedpoint_test_operator("^",is,ds,n,0,1,0) ||
470 ## Can't divide by a matrix as don't have inversion
471 _fixedpoint_test_operator("/",is,ds,n,0,1,0) ||
472 _fixedpoint_test_operator("\\",is,ds,n,0,0,1))
478 fprintf("\n<< Fixed Point Functions >>\n");
479 fprintf(" Rounding Functions: ");
481 if (_fixedpoint_test_function("ceil",is,ds,n,0) ||
482 _fixedpoint_test_function("floor",is,ds,n,0) ||
483 _fixedpoint_test_function("round",is,ds,n,0))
489 fprintf(" Matrix Sum and Product Functions: ");
490 if (_fixedpoint_test_function("sum",is,ds,n,0) ||
491 _fixedpoint_test_function("cumsum",is,ds,n,0))
495 ## These can easily under- or over-flow. Trick the code by
496 ## foring ds=0, which simplifies the internal calculations,
497 ## effectively limiting the values used to 1 and 0. If you
498 ## can think of a better way, tell me...
501 if (_fixedpoint_test_function("sumsq",is,ds,n,feps) ||
502 _fixedpoint_test_function("prod",is,ds,n,feps) ||
503 _fixedpoint_test_function("cumprod",is,ds,n,feps))
510 fprintf(" Miscellaneous Functions: ");
511 if (_fixedpoint_test_function("real",is,ds,n,0) ||
512 _fixedpoint_test_function("imag",is,ds,n,0) ||
513 _fixedpoint_test_function("conj",is,ds,n,0) ||
514 _fixedpoint_test_function("arg",is,ds,n,feps) ||
515 _fixedpoint_test_function("angle",is,ds,n,feps) ||
516 _fixedpoint_test_function("abs",is,ds,n,sqrt(2)*feps) ||
517 _fixedpoint_test_function("sqrt",is,ds,n,sqrt(2)*feps))
523 ## These will underflow/overflow, use larger feps that should be
524 ## ok upto ds = 6. Again if you can think of a better way to check!!
525 fprintf(" Exponential Functions: ");
526 if (_fixedpoint_test_function("log",is,ds,n,2*feps,0) ||
527 _fixedpoint_test_function("log10",is,ds,n,20*feps,0) ||
528 _fixedpoint_test_function("exp",is,ds,n,4*feps))
534 ## These will underflow/overflow, use larger feps that should be
535 ## ok upto ds = 6. Again if you can think of a better way to check!!
536 fprintf(" Trigonometric Functions: ");
537 if (_fixedpoint_test_function("sin",is,ds,n,4*feps) ||
538 _fixedpoint_test_function("sinh",is,ds,n,4*feps) ||
539 _fixedpoint_test_function("cos",is,ds,n,4*feps) ||
540 _fixedpoint_test_function("cosh",is,ds,n,4*feps) ||
541 _fixedpoint_test_function("tan",is,ds,n,4*feps) ||
542 _fixedpoint_test_function("tanh",is,ds,n,4*feps))
546 ## Special case for fatan2
547 fzero = fixed(is,ds,0);
548 fzeros = fixed(is,ds,zeros(n,1));
549 fone = fixed(is,ds,1);
550 fones = fixed(is,ds,ones(n,1));
551 fpi2 = fixed(is,ds,pi/2);
552 fpi4 = fixed(is,ds,pi/4);
553 if (fatan2(fzero,fzero) != fzero ||
554 fatan2(fzero,fone) != fzero ||
555 fatan2(fone,fzero) != fpi2 ||
556 fatan2(fone,fone) != fpi4 ||
557 any(fatan2(fzeros,fzeros) != fzero) ||
558 any(fatan2(fzeros,fones) != fzero) ||
559 any(fatan2(fones,fzeros) != fpi2) ||
560 any(fatan2(fones,fones) != fpi4))
567 unwind_protect_cleanup
568 page_screen_output(pso);
571 usage("fixedpoint: Unknown argument");
575 function ret = _fixedpoint_test_operator(op,is,ds,n,includezero,matrixleft,
577 # Properly test all 16 possible combinations of an operator
586 tczeros = 1i*ones(n,n);
588 tcones = (1 + 1i)*ones(n,n);
590 fzero = fixed(is,ds,tzero);
591 fone = fixed(is,ds,tone);
592 fzeros = fixed(is,ds,tzeros);
593 fones = fixed(is,ds,tones);
594 fczero = fixed(is,ds,tczero);
595 fczeros = fixed(is,ds,tczeros);
596 fcone = fixed(is,ds,tcone);
597 fcones = fixed(is,ds,tcones);
601 t1 = eval(["tzero" op "tzero;"]);
602 f1 = eval(["fzero" op "fzero;"]);
607 t1 = eval(["tzero" op "tone;"]);
608 f1 = eval(["fzero" op "fone;"]);
613 t1 = eval(["tone" op "tzero;"]);
614 f1 = eval(["fone" op "fzero;"]);
620 t1 = eval(["tone" op "tone;"]);
621 f1 = eval(["fone" op "fone;"]);
630 t1 = eval(["tzero" op "tzeros;"]);
631 f1 = eval(["fzero" op "fzeros;"]);
632 if any(any(t1 != f1.x))
636 t1 = eval(["tzero" op "tones;"]);
637 f1 = eval(["fzero" op "fones;"]);
638 if any(any(t1 != f1.x))
642 t1 = eval(["tone" op "tzeros;"]);
643 f1 = eval(["fone" op "fzeros;"]);
644 if any(any(t1 != f1.x))
649 t1 = eval(["tone" op "tones;"]);
650 f1 = eval(["fone" op "fones;"]);
651 if any(any(t1 != f1.x))
660 t1 = eval(["tzeros" op "tzero;"]);
661 f1 = eval(["fzeros" op "fzero;"]);
662 if any(any(t1 != f1.x))
666 t1 = eval(["tzeros" op "tone;"]);
667 f1 = eval(["fzeros" op "fone;"]);
668 if any(any(t1 != f1.x))
672 t1 = eval(["tones" op "tzero;"]);
673 f1 = eval(["fones" op "fzero;"]);
674 if any(any(t1 != f1.x))
679 t1 = eval(["tones" op "tone;"]);
680 f1 = eval(["fones" op "fone;"]);
681 if any(any(t1 != f1.x))
688 if (matrixleft && matrixright)
690 t1 = eval(["tzeros" op "tzeros;"]);
691 f1 = eval(["fzeros" op "fzeros;"]);
692 if any(any(t1 != f1.x))
696 t1 = eval(["tzeros" op "tones;"]);
697 f1 = eval(["fzeros" op "fones;"]);
698 if any(any(t1 != f1.x))
702 t1 = eval(["tones" op "tzeros;"]);
703 f1 = eval(["fones" op "fzeros;"]);
704 if any(any(t1 != f1.x))
709 t1 = eval(["tones" op "tones;"]);
710 f1 = eval(["fones" op "fones;"]);
711 if any(any(t1 != f1.x))
717 # scalar by complex scalar
719 t1 = eval(["tzero" op "tczero;"]);
720 f1 = eval(["fzero" op "fczero;"]);
725 t1 = eval(["tzero" op "tcone;"]);
726 f1 = eval(["fzero" op "fcone;"]);
732 t1 = eval(["tone" op "tczero;"]);
733 f1 = eval(["fone" op "fczero;"]);
738 t1 = eval(["tone" op "tcone;"]);
739 f1 = eval(["fone" op "fcone;"]);
745 # scalar by complex matrix
748 t1 = eval(["tzero" op "tczeros;"]);
749 f1 = eval(["fzero" op "fczeros;"]);
750 if any(any(t1 != f1.x))
754 t1 = eval(["tzero" op "tcones;"]);
755 f1 = eval(["fzero" op "fcones;"]);
756 if any(any(t1 != f1.x))
761 t1 = eval(["tone" op "tczeros;"]);
762 f1 = eval(["fone" op "fczeros;"]);
763 if any(any(t1 != f1.x))
767 t1 = eval(["tone" op "tcones;"]);
768 f1 = eval(["fone" op "fcones;"]);
769 if any(any(t1 != f1.x))
775 # matrix by complex scalar
778 t1 = eval(["tzeros" op "tczero;"]);
779 f1 = eval(["fzeros" op "fczero;"]);
780 if any(any(t1 != f1.x))
784 t1 = eval(["tzeros" op "tcone;"]);
785 f1 = eval(["fzeros" op "fcone;"]);
786 if any(any(t1 != f1.x))
791 t1 = eval(["tones" op "tczero;"]);
792 f1 = eval(["fones" op "fczero;"]);
793 if any(any(t1 != f1.x))
797 t1 = eval(["tones" op "tcone;"]);
798 f1 = eval(["fones" op "fcone;"]);
799 if any(any(t1 != f1.x))
805 # matrix by complex matrix
806 if (matrixleft && matrixright)
808 t1 = eval(["tzeros" op "tczeros;"]);
809 f1 = eval(["fzeros" op "fczeros;"]);
810 if any(any(t1 != f1.x))
814 t1 = eval(["tzeros" op "tcones;"]);
815 f1 = eval(["fzeros" op "fcones;"]);
816 if any(any(t1 != f1.x))
821 t1 = eval(["tones" op "tczeros;"]);
822 f1 = eval(["fones" op "fczeros;"]);
823 if any(any(t1 != f1.x))
827 t1 = eval(["tones" op "tcones;"]);
828 f1 = eval(["fones" op "fcones;"]);
829 if any(any(t1 != f1.x))
835 # complex scalar by scalar
837 t1 = eval(["tczero" op "tzero;"]);
838 f1 = eval(["fczero" op "fzero;"]);
843 t1 = eval(["tcone" op "tzero;"]);
844 f1 = eval(["fcone" op "fzero;"]);
850 t1 = eval(["tczero" op "tone;"]);
851 f1 = eval(["fczero" op "fone;"]);
856 t1 = eval(["tcone" op "tone;"]);
857 f1 = eval(["fcone" op "fone;"]);
863 # complex scalar by matrix
866 t1 = eval(["tczero" op "tzeros;"]);
867 f1 = eval(["fczero" op "fzeros;"]);
868 if any(any(t1 != f1.x))
872 t1 = eval(["tcone" op "tzeros;"]);
873 f1 = eval(["fcone" op "fzeros;"]);
874 if any(any(t1 != f1.x))
879 t1 = eval(["tczero" op "tones;"]);
880 f1 = eval(["fczero" op "fones;"]);
881 if any(any(t1 != f1.x))
885 t1 = eval(["tcone" op "tones;"]);
886 f1 = eval(["fcone" op "fones;"]);
887 if any(any(t1 != f1.x))
893 # complex matrix by scalar
896 t1 = eval(["tczeros" op "tzero;"]);
897 f1 = eval(["fczeros" op "fzero;"]);
898 if any(any(t1 != f1.x))
902 t1 = eval(["tcones" op "tzero;"]);
903 f1 = eval(["fcones" op "fzero;"]);
904 if any(any(t1 != f1.x))
909 t1 = eval(["tczeros" op "tone;"]);
910 f1 = eval(["fczeros" op "fone;"]);
911 if any(any(t1 != f1.x))
915 t1 = eval(["tcones" op "tone;"]);
916 f1 = eval(["fcones" op "fone;"]);
917 if any(any(t1 != f1.x))
923 # complex matrix by matrix
924 if (matrixleft && matrixright)
926 t1 = eval(["tczeros" op "tzeros;"]);
927 f1 = eval(["fczeros" op "fzeros;"]);
928 if any(any(t1 != f1.x))
932 t1 = eval(["tcones" op "tzeros;"]);
933 f1 = eval(["fcones" op "fzeros;"]);
934 if any(any(t1 != f1.x))
939 t1 = eval(["tczeros" op "tones;"]);
940 f1 = eval(["fczeros" op "fones;"]);
941 if any(any(t1 != f1.x))
945 t1 = eval(["tcones" op "tones;"]);
946 f1 = eval(["fcones" op "fones;"]);
947 if any(any(t1 != f1.x))
953 # complex scalar by complex scalar
954 t1 = eval(["tczero" op "tczero;"]);
955 f1 = eval(["fczero" op "fczero;"]);
960 t1 = eval(["tczero" op "tcone;"]);
961 f1 = eval(["fczero" op "fcone;"]);
966 t1 = eval(["tcone" op "tczero;"]);
967 f1 = eval(["fcone" op "fczero;"]);
972 t1 = eval(["tcone" op "tcone;"]);
973 f1 = eval(["fcone" op "fcone;"]);
979 # complex scalar by complex matrix
981 t1 = eval(["tczero" op "tczeros;"]);
982 f1 = eval(["fczero" op "fczeros;"]);
983 if any(any(t1 != f1.x))
987 t1 = eval(["tczero" op "tcones;"]);
988 f1 = eval(["fczero" op "fcones;"]);
989 if any(any(t1 != f1.x))
993 t1 = eval(["tcone" op "tczeros;"]);
994 f1 = eval(["fcone" op "fczeros;"]);
995 if any(any(t1 != f1.x))
999 t1 = eval(["tcone" op "tcones;"]);
1000 f1 = eval(["fcone" op "fcones;"]);
1001 if any(any(t1 != f1.x))
1007 # complex matrix by complex scalar
1009 t1 = eval(["tczeros" op "tczero;"]);
1010 f1 = eval(["fczeros" op "fczero;"]);
1011 if any(any(t1 != f1.x))
1015 t1 = eval(["tczeros" op "tcone;"]);
1016 f1 = eval(["fczeros" op "fcone;"]);
1017 if any(any(t1 != f1.x))
1021 t1 = eval(["tcones" op "tczero;"]);
1022 f1 = eval(["fcones" op "fczero;"]);
1023 if any(any(t1 != f1.x))
1027 t1 = eval(["tcones" op "tcone;"]);
1028 f1 = eval(["fcones" op "fcone;"]);
1029 if any(any(t1 != f1.x))
1035 # complex matrix by complex matrix
1036 if (matrixleft && matrixright)
1037 t1 = eval(["tczeros" op "tczeros;"]);
1038 f1 = eval(["fczeros" op "fczeros;"]);
1039 if any(any(t1 != f1.x))
1043 t1 = eval(["tczeros" op "tcones;"]);
1044 f1 = eval(["fczeros" op "fcones;"]);
1045 if any(any(t1 != f1.x))
1049 t1 = eval(["tcones" op "tczeros;"]);
1050 f1 = eval(["fcones" op "fczeros;"]);
1051 if any(any(t1 != f1.x))
1055 t1 = eval(["tcones" op "tcones;"]);
1056 f1 = eval(["fcones" op "fcones;"]);
1057 if any(any(t1 != f1.x))
1065 function ret = _fixedpoint_test_bool_operator(op,is,ds,n)
1066 # Properly test all 16 possible combinations of an operator
1072 tzeros = zeros(n,n);
1075 tczeros = 1i*ones(n,n);
1077 tcones = (1 + 1i)*ones(n,n);
1079 fzero = fixed(is,ds,tzero);
1080 fone = fixed(is,ds,tone);
1081 fzeros = fixed(is,ds,tzeros);
1082 fones = fixed(is,ds,tones);
1083 fczero = fixed(is,ds,tczero);
1084 fczeros = fixed(is,ds,tczeros);
1085 fcone = fixed(is,ds,tcone);
1086 fcones = fixed(is,ds,tcones);
1089 t1 = eval(["tzero" op "tzero;"]);
1090 f1 = eval(["fzero" op "fzero;"]);
1095 t1 = eval(["tzero" op "tone;"]);
1096 f1 = eval(["fzero" op "fone;"]);
1101 t1 = eval(["tone" op "tzero;"]);
1102 f1 = eval(["fone" op "fzero;"]);
1107 t1 = eval(["tone" op "tone;"]);
1108 f1 = eval(["fone" op "fone;"]);
1115 t1 = eval(["tzero" op "tzeros;"]);
1116 f1 = eval(["fzero" op "fzeros;"]);
1117 if any(any(t1 != f1))
1121 t1 = eval(["tzero" op "tones;"]);
1122 f1 = eval(["fzero" op "fones;"]);
1123 if any(any(t1 != f1))
1127 t1 = eval(["tone" op "tzeros;"]);
1128 f1 = eval(["fone" op "fzeros;"]);
1129 if any(any(t1 != f1))
1133 t1 = eval(["tone" op "tones;"]);
1134 f1 = eval(["fone" op "fones;"]);
1135 if any(any(t1 != f1))
1141 t1 = eval(["tzeros" op "tzero;"]);
1142 f1 = eval(["fzeros" op "fzero;"]);
1143 if any(any(t1 != f1))
1147 t1 = eval(["tzeros" op "tone;"]);
1148 f1 = eval(["fzeros" op "fone;"]);
1149 if any(any(t1 != f1))
1153 t1 = eval(["tones" op "tzero;"]);
1154 f1 = eval(["fones" op "fzero;"]);
1155 if any(any(t1 != f1))
1159 t1 = eval(["tones" op "tone;"]);
1160 f1 = eval(["fones" op "fone;"]);
1161 if any(any(t1 != f1))
1167 t1 = eval(["tzeros" op "tzeros;"]);
1168 f1 = eval(["fzeros" op "fzeros;"]);
1169 if any(any(t1 != f1))
1173 t1 = eval(["tzeros" op "tones;"]);
1174 f1 = eval(["fzeros" op "fones;"]);
1175 if any(any(t1 != f1))
1179 t1 = eval(["tones" op "tzeros;"]);
1180 f1 = eval(["fones" op "fzeros;"]);
1181 if any(any(t1 != f1))
1185 t1 = eval(["tones" op "tones;"]);
1186 f1 = eval(["fones" op "fones;"]);
1187 if any(any(t1 != f1))
1193 # scalar by complex scalar
1194 t1 = eval(["tzero" op "tczero;"]);
1195 f1 = eval(["fzero" op "fczero;"]);
1200 t1 = eval(["tzero" op "tcone;"]);
1201 f1 = eval(["fzero" op "fcone;"]);
1206 t1 = eval(["tone" op "tczero;"]);
1207 f1 = eval(["fone" op "fczero;"]);
1212 t1 = eval(["tone" op "tcone;"]);
1213 f1 = eval(["fone" op "fcone;"]);
1219 # scalar by complex matrix
1220 t1 = eval(["tzero" op "tczeros;"]);
1221 f1 = eval(["fzero" op "fczeros;"]);
1222 if any(any(t1 != f1))
1226 t1 = eval(["tzero" op "tcones;"]);
1227 f1 = eval(["fzero" op "fcones;"]);
1228 if any(any(t1 != f1))
1232 t1 = eval(["tone" op "tczeros;"]);
1233 f1 = eval(["fone" op "fczeros;"]);
1234 if any(any(t1 != f1))
1238 t1 = eval(["tone" op "tcones;"]);
1239 f1 = eval(["fone" op "fcones;"]);
1240 if any(any(t1 != f1))
1245 # matrix by complex scalar
1246 t1 = eval(["tzeros" op "tczero;"]);
1247 f1 = eval(["fzeros" op "fczero;"]);
1248 if any(any(t1 != f1))
1252 t1 = eval(["tzeros" op "tcone;"]);
1253 f1 = eval(["fzeros" op "fcone;"]);
1254 if any(any(t1 != f1))
1258 t1 = eval(["tones" op "tczero;"]);
1259 f1 = eval(["fones" op "fczero;"]);
1260 if any(any(t1 != f1))
1264 t1 = eval(["tones" op "tcone;"]);
1265 f1 = eval(["fones" op "fcone;"]);
1266 if any(any(t1 != f1))
1271 # matrix by complex matrix
1272 t1 = eval(["tzeros" op "tczeros;"]);
1273 f1 = eval(["fzeros" op "fczeros;"]);
1274 if any(any(t1 != f1))
1278 t1 = eval(["tzeros" op "tcones;"]);
1279 f1 = eval(["fzeros" op "fcones;"]);
1280 if any(any(t1 != f1))
1284 t1 = eval(["tones" op "tczeros;"]);
1285 f1 = eval(["fones" op "fczeros;"]);
1286 if any(any(t1 != f1))
1290 t1 = eval(["tones" op "tcones;"]);
1291 f1 = eval(["fones" op "fcones;"]);
1292 if any(any(t1 != f1))
1297 # complex scalar by scalar
1298 t1 = eval(["tczero" op "tzero;"]);
1299 f1 = eval(["fczero" op "fzero;"]);
1304 t1 = eval(["tczero" op "tone;"]);
1305 f1 = eval(["fczero" op "fone;"]);
1310 t1 = eval(["tcone" op "tzero;"]);
1311 f1 = eval(["fcone" op "fzero;"]);
1316 t1 = eval(["tcone" op "tone;"]);
1317 f1 = eval(["fcone" op "fone;"]);
1323 # complex scalar by matrix
1324 t1 = eval(["tczero" op "tzeros;"]);
1325 f1 = eval(["fczero" op "fzeros;"]);
1326 if any(any(t1 != f1))
1330 t1 = eval(["tczero" op "tones;"]);
1331 f1 = eval(["fczero" op "fones;"]);
1332 if any(any(t1 != f1))
1336 t1 = eval(["tcone" op "tzeros;"]);
1337 f1 = eval(["fcone" op "fzeros;"]);
1338 if any(any(t1 != f1))
1342 t1 = eval(["tcone" op "tones;"]);
1343 f1 = eval(["fcone" op "fones;"]);
1344 if any(any(t1 != f1))
1349 # complex matrix by scalar
1350 t1 = eval(["tczeros" op "tzero;"]);
1351 f1 = eval(["fczeros" op "fzero;"]);
1352 if any(any(t1 != f1))
1356 t1 = eval(["tczeros" op "tone;"]);
1357 f1 = eval(["fczeros" op "fone;"]);
1358 if any(any(t1 != f1))
1362 t1 = eval(["tcones" op "tzero;"]);
1363 f1 = eval(["fcones" op "fzero;"]);
1364 if any(any(t1 != f1))
1368 t1 = eval(["tcones" op "tone;"]);
1369 f1 = eval(["fcones" op "fone;"]);
1370 if any(any(t1 != f1))
1375 # complex matrix by matrix
1376 t1 = eval(["tczeros" op "tzeros;"]);
1377 f1 = eval(["fczeros" op "fzeros;"]);
1378 if any(any(t1 != f1))
1382 t1 = eval(["tczeros" op "tones;"]);
1383 f1 = eval(["fczeros" op "fones;"]);
1384 if any(any(t1 != f1))
1388 t1 = eval(["tcones" op "tzeros;"]);
1389 f1 = eval(["fcones" op "fzeros;"]);
1390 if any(any(t1 != f1))
1394 t1 = eval(["tcones" op "tones;"]);
1395 f1 = eval(["fcones" op "fones;"]);
1396 if any(any(t1 != f1))
1401 # complex scalar by complex scalar
1402 t1 = eval(["tczero" op "tczero;"]);
1403 f1 = eval(["fczero" op "fczero;"]);
1408 t1 = eval(["tczero" op "tcone;"]);
1409 f1 = eval(["fczero" op "fcone;"]);
1414 t1 = eval(["tcone" op "tczero;"]);
1415 f1 = eval(["fcone" op "fczero;"]);
1420 t1 = eval(["tcone" op "tcone;"]);
1421 f1 = eval(["fcone" op "fcone;"]);
1427 # complex scalar by complex matrix
1428 t1 = eval(["tczero" op "tczeros;"]);
1429 f1 = eval(["fczero" op "fczeros;"]);
1430 if any(any(t1 != f1))
1434 t1 = eval(["tczero" op "tcones;"]);
1435 f1 = eval(["fczero" op "fcones;"]);
1436 if any(any(t1 != f1))
1440 t1 = eval(["tcone" op "tczeros;"]);
1441 f1 = eval(["fcone" op "fczeros;"]);
1442 if any(any(t1 != f1))
1446 t1 = eval(["tcone" op "tcones;"]);
1447 f1 = eval(["fcone" op "fcones;"]);
1448 if any(any(t1 != f1))
1453 # complex matrix by complex scalar
1454 t1 = eval(["tczeros" op "tczero;"]);
1455 f1 = eval(["fczeros" op "fczero;"]);
1456 if any(any(t1 != f1))
1460 t1 = eval(["tczeros" op "tcone;"]);
1461 f1 = eval(["fczeros" op "fcone;"]);
1462 if any(any(t1 != f1))
1466 t1 = eval(["tcones" op "tczero;"]);
1467 f1 = eval(["fcones" op "fczero;"]);
1468 if any(any(t1 != f1))
1472 t1 = eval(["tcones" op "tcone;"]);
1473 f1 = eval(["fcones" op "fcone;"]);
1474 if any(any(t1 != f1))
1479 # complex matrix by complex matrix
1480 t1 = eval(["tczeros" op "tczeros;"]);
1481 f1 = eval(["fczeros" op "fczeros;"]);
1482 if any(any(t1 != f1))
1486 t1 = eval(["tczeros" op "tcones;"]);
1487 f1 = eval(["fczeros" op "fcones;"]);
1488 if any(any(t1 != f1))
1492 t1 = eval(["tcones" op "tczeros;"]);
1493 f1 = eval(["fcones" op "fczeros;"]);
1494 if any(any(t1 != f1))
1498 t1 = eval(["tcones" op "tcones;"]);
1499 f1 = eval(["fcones" op "fcones;"]);
1500 if any(any(t1 != f1))
1507 function ret = _fixedpoint_test_unary_operator(op,is,ds,n,front)
1508 # Properly test all 4 possible combinations of an operator
1514 tzeros = zeros(n,n);
1517 tczeros = 1i*ones(n,n);
1519 tcones = (1 + 1i)*ones(n,n);
1521 fzero = fixed(is,ds,tzero);
1522 fone = fixed(is,ds,tone);
1523 fzeros = fixed(is,ds,tzeros);
1524 fones = fixed(is,ds,tones);
1525 fczero = fixed(is,ds,tczero);
1526 fczeros = fixed(is,ds,tczeros);
1527 fcone = fixed(is,ds,tcone);
1528 fcones = fixed(is,ds,tcones);
1539 t1 = eval([ op1 "tzero" op2 ";"]);
1540 f1 = eval([ op1 "fzero" op2 ";"]);
1545 t1 = eval([ op1 "tone" op2 ";"]);
1546 f1 = eval([ op1 "fone" op2 ";"]);
1553 t1 = eval([ op1 "tzeros" op2 ";"]);
1554 f1 = eval([ op1 "fzeros" op2 ";"]);
1555 if any(any(t1 != f1.x))
1559 t1 = eval([ op1 "tones" op2 ";"]);
1560 f1 = eval([ op1 "fones" op2 ";"]);
1561 if any(any(t1 != f1.x))
1567 t1 = eval([ op1 "tczero" op2 ";"]);
1568 f1 = eval([ op1 "fczero" op2 ";"]);
1573 t1 = eval([ op1 "tcone" op2 ";"]);
1574 f1 = eval([ op1 "fcone" op2 ";"]);
1581 t1 = eval([ op1 "tczeros" op2 ";"]);
1582 f1 = eval([ op1 "fczeros" op2 ";"]);
1583 if any(any(t1 != f1.x))
1587 t1 = eval([ op1 "tcones" op2 ";"]);
1588 f1 = eval([ op1 "fcones" op2 ";"]);
1589 if any(any(t1 != f1.x))
1596 function ret = _fixedpoint_test_function(func,is,ds,n,eps,includezero)
1597 # Properly test all 4 possible combinations of a function
1606 tzeros = zeros(n,n);
1609 tczeros = 1i*ones(n,n);
1611 tcones = (1 + 1i)*ones(n,n);
1620 tvals = ones(n,1) * (round(2^ds * (0:(n-1))/(n-1)) / 2^ds);
1622 tvals = ones(n,1) * (round(2^ds * (1 + 2^(is-1)*(1:(n-1))/(n-1)))
1625 tcval = tval * (1+1i);
1626 tcvals = tvals * (1+1i);
1629 fzero = fixed(is,ds,tzero);
1630 fone = fixed(is,ds,tone);
1631 fzeros = fixed(is,ds,tzeros);
1632 fones = fixed(is,ds,tones);
1633 fczero = fixed(is,ds,tczero);
1634 fczeros = fixed(is,ds,tczeros);
1635 fcone = fixed(is,ds,tcone);
1636 fcones = fixed(is,ds,tcones);
1637 fval = fixed(is,ds,tval);
1638 fvals = fixed(is,ds,tvals);
1639 fcval = fixed(is,ds,tcval);
1640 fcvals = fixed(is,ds,tcvals);
1642 ffunc = [ "f" func];
1646 t1 = eval([ func "(tzero);"]);
1647 f1 = eval([ ffunc "(fzero);"]);
1648 if (abs(t1 - f1.x) > eps)
1653 t1 = eval([ func "(tone);"]);
1654 f1 = eval([ ffunc "(fone);"]);
1655 if (abs(t1 - f1.x) > eps)
1659 t1 = eval([ func "(tval);"]);
1660 f1 = eval([ ffunc "(fval);"]);
1661 if (abs(t1 - f1.x) > eps)
1668 t1 = eval([ func "(tzeros);"]);
1669 f1 = eval([ ffunc "(fzeros);"]);
1670 if any(any(abs(t1 - f1.x) > eps))
1675 t1 = eval([ func "(tones);"]);
1676 f1 = eval([ ffunc "(fones);"]);
1677 if any(any(abs(t1 - f1.x) > eps))
1681 t1 = eval([ func "(tvals);"]);
1682 f1 = eval([ ffunc "(fvals);"]);
1683 if any(any(abs(t1 - f1.x) > eps))
1690 t1 = eval([ func "(tczero);"]);
1691 f1 = eval([ ffunc "(fczero);"]);
1692 if ((abs(real(t1) - freal(f1).x) > eps) ||
1693 (abs(imag(t1) - fimag(f1).x) > eps))
1698 t1 = eval([ func "(tcone);"]);
1699 f1 = eval([ ffunc "(fcone);"]);
1700 if ((abs(real(t1) - freal(f1).x) > eps) || (abs(imag(t1) - fimag(f1).x) > eps))
1704 t1 = eval([ func "(tcval);"]);
1705 f1 = eval([ ffunc "(fcval);"]);
1706 if ((abs(real(t1) - freal(f1).x) > eps) || (abs(imag(t1) - fimag(f1).x) > eps))
1713 t1 = eval([ func "(tczeros);"]);
1714 f1 = eval([ ffunc "(fczeros);"]);
1715 if (any(any(abs(real(t1) - freal(f1).x) > eps)) ||
1716 any(any(abs(imag(t1) - fimag(f1).x) > eps)))
1721 t1 = eval([ func "(tcones);"]);
1722 f1 = eval([ ffunc "(fcones);"]);
1723 if (any(any(abs(real(t1) - freal(f1).x) > eps)) ||
1724 any(any(abs(imag(t1) - fimag(f1).x) > eps)))
1728 t1 = eval([ func "(tcvals);"]);
1729 f1 = eval([ ffunc "(fcvals);"]);
1730 if (any(any(abs(real(t1) - freal(f1).x) > eps)) ||
1731 any(any(abs(imag(t1) - fimag(f1).x) > eps)))
1739 %! try fixedpoint("test");
1740 %! catch disp(lasterr()); end
1742 ## Local Variables: ***