annotate src/DLD-FUNCTIONS/gcd.cc @ 10154:40dfc0c99116

DLD-FUNCTIONS/*.cc: untabify
author John W. Eaton <jwe@octave.org>
date Wed, 20 Jan 2010 17:33:41 -0500
parents 1231b1762a9a
children d0ce5e973937
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
1 /*
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
2
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8517
diff changeset
3 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 David Bateman
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
4
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
5 This file is part of Octave.
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
6
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 under the terms of the GNU General Public License as published by the
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
10 option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
11
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
15 for more details.
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
16
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
19 <http://www.gnu.org/licenses/>.
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
20
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
21 */
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
22
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
25 #endif
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
26
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
27 #include "dNDArray.h"
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
28 #include "CNDArray.h"
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
29 #include "fNDArray.h"
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
30 #include "fCNDArray.h"
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
31 #include "lo-mappers.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 7815
diff changeset
32 #include "oct-locbuf.h"
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
33
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
34 #include "defun-dld.h"
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
35 #include "error.h"
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
36 #include "oct-obj.h"
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
37
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5642
diff changeset
38 // FIXME -- should probably handle Inf, NaN.
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
39
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
40 static inline bool
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
41 is_integer_value (double x)
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
42 {
5985
5f662c1cfbbe [project @ 2006-09-12 02:41:46 by jwe]
jwe
parents: 5964
diff changeset
43 return x == std::floor (x);
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
44 }
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
45
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
46 static inline bool
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
47 is_integer_value (float x)
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
48 {
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
49 return x == std::floor (x);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
50 }
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
51
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
52 DEFUN_DLD (gcd, args, nargout,
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
53 "-*- texinfo -*-\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
54 @deftypefn {Loadable Function} {@var{g} =} gcd (@var{a})\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
55 @deftypefnx {Loadable Function} {@var{g} =} gcd (@var{a1}, @var{a2}, @dots{})\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
56 @deftypefnx {Loadable Function} {[@var{g}, @var{v1}, @dots{}] =} gcd (@var{a1}, @var{a2}, @dots{})\n\
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
57 \n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
58 Compute the greatest common divisor of the elements of @var{a}. If more\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
59 than one argument is given all arguments must be the same size or scalar.\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
60 In this case the greatest common divisor is calculated for each element\n\
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
61 individually. All elements must be integers. For example,\n\
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
62 \n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
63 @example\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
64 @group\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
65 gcd ([15, 20])\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
66 @result{} 5\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
67 @end group\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
68 @end example\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
69 \n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
70 @noindent\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
71 and\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
72 \n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
73 @example\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
74 @group\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
75 gcd ([15, 9], [20, 18])\n\
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
76 @result{} 5 9\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
77 @end group\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
78 @end example\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
79 \n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
80 Optional return arguments @var{v1}, etc., contain integer vectors such\n\
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
81 that,\n\
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
82 \n\
9167
1231b1762a9a Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9141
diff changeset
83 @tex\n\
1231b1762a9a Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9141
diff changeset
84 $g = v_1 a_1 + v_2 a_2 + \\cdots$\n\
1231b1762a9a Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9141
diff changeset
85 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8377
diff changeset
86 @ifnottex\n\
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
87 @example\n\
6547
4fb053f24fd6 [project @ 2007-04-19 21:47:40 by jwe]
jwe
parents: 5985
diff changeset
88 @var{g} = @var{v1} .* @var{a1} + @var{v2} .* @var{a2} + @dots{}\n\
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
89 @end example\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8377
diff changeset
90 @end ifnottex\n\
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
91 \n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6547
diff changeset
92 For backward compatibility with previous versions of this function, when\n\
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6547
diff changeset
93 all arguments are scalar, a single return argument @var{v1} containing\n\
6547
4fb053f24fd6 [project @ 2007-04-19 21:47:40 by jwe]
jwe
parents: 5985
diff changeset
94 all of the values of @var{v1}, @dots{} is acceptable.\n\
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
95 @seealso{lcm, factor}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
96 @end deftypefn")
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
97 {
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
98 octave_value_list retval;
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
99
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
100 int nargin = args.length ();
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
101
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
102 if (nargin == 0)
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
103 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
104 print_usage ();
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
105 return retval;
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
106 }
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
107
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
108 bool all_args_scalar = true;
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
109 bool any_single = false;
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
110
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
111 dim_vector dv(1);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
112
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
113 for (int i = 0; i < nargin; i++)
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
114 {
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
115 if (! args(i).is_scalar_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
116 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
117 if (! args(i).is_matrix_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
118 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
119 error ("gcd: invalid argument type");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
120 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
121 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
122
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
123 if (all_args_scalar)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
124 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
125 all_args_scalar = false;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
126 dv = args(i).dims ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
127 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
128 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
129 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
130 if (dv != args(i).dims ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
131 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
132 error ("gcd: all arguments must be the same size or scalar");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
133 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
134 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
135 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
136 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
137 if (!any_single && args(i).is_single_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
138 any_single = true;
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
139 }
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
140
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
141 if (any_single)
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
142 {
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
143 if (nargin == 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
144 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
145 FloatNDArray gg = args(0).float_array_value ();
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
146
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
147 int nel = dv.numel ();
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
148
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
149 FloatNDArray v (dv);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
150
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
151 FloatRowVector x (3);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
152 FloatRowVector y (3);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
153
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
154 float g = std::abs (gg(0));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
155
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
156 if (! is_integer_value (g))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
157 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
158 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
159 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
160 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
161
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
162 v(0) = signum (gg(0));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
163
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
164 for (int k = 1; k < nel; k++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
165 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
166 x(0) = g;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
167 x(1) = 1;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
168 x(2) = 0;
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
169
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
170 y(0) = std::abs (gg(k));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
171 y(1) = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
172 y(2) = 1;
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
173
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
174 if (! is_integer_value (y(0)))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
175 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
176 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
177 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
178 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
179
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
180 while (y(0) > 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
181 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
182 FloatRowVector r = x - y * std::floor (x(0) / y(0));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
183 x = y;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
184 y = r;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
185 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
186
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
187 g = x(0);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
188
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
189 for (int i = 0; i < k; i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
190 v(i) *= x(1);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
191
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
192 v(k) = x(2) * signum (gg(k));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
193 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
194
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
195 retval (1) = v;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
196 retval (0) = g;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
197 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
198 else if (all_args_scalar && nargout < 3)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
199 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
200 float g = args(0).float_value ();
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
201
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
202 if (error_state || ! is_integer_value (g))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
203 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
204 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
205 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
206 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
207
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
208 FloatRowVector v (nargin, 0);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
209 FloatRowVector x (3);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
210 FloatRowVector y (3);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
211
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
212 v(0) = signum (g);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
213
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
214 g = std::abs(g);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
215
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
216 for (int k = 1; k < nargin; k++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
217 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
218 x(0) = g;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
219 x(1) = 1;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
220 x(2) = 0;
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
221
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
222 y(0) = args(k).float_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
223 y(1) = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
224 y(2) = 1;
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
225
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
226 float sgn = signum (y(0));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
227
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
228 y(0) = std::abs (y(0));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
229
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
230 if (error_state || ! is_integer_value (g))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
231 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
232 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
233 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
234 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
235
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
236 while (y(0) > 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
237 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
238 FloatRowVector r = x - y * std::floor (x(0) / y(0));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
239 x = y;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
240 y = r;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
241 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
242
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
243 g = x(0);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
244
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
245 for (int i = 0; i < k; i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
246 v(i) *= x(1);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
247
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
248 v(k) = x(2) * sgn;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
249 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
250
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
251 retval (1) = v;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
252 retval (0) = g;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
253 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
254 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
255 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
256 // FIXME -- we need to handle a possible mixture of scalar and
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
257 // array values here.
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
258
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
259 FloatNDArray g = args(0).float_array_value ();
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
260
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
261 OCTAVE_LOCAL_BUFFER (FloatNDArray, v, nargin);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
262
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
263 int nel = dv.numel ();
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
264
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
265 v[0].resize(dv);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
266
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
267 for (int i = 0; i < nel; i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
268 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
269 v[0](i) = signum (g(i));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
270 g(i) = std::abs (g(i));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
271
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
272 if (! is_integer_value (g(i)))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
273 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
274 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
275 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
276 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
277 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
278
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
279 FloatRowVector x (3);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
280 FloatRowVector y (3);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
281
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
282 for (int k = 1; k < nargin; k++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
283 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
284 FloatNDArray gnew = args(k).float_array_value ();
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
285
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
286 v[k].resize(dv);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
287
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
288 for (int n = 0; n < nel; n++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
289 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
290 x(0) = g(n);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
291 x(1) = 1;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
292 x(2) = 0;
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
293
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
294 y(0) = std::abs (gnew(n));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
295 y(1) = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
296 y(2) = 1;
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
297
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
298 if (! is_integer_value (y(0)))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
299 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
300 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
301 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
302 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
303
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
304 while (y(0) > 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
305 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
306 FloatRowVector r = x - y * std::floor (x(0) / y(0));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
307 x = y;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
308 y = r;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
309 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
310
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
311 g(n) = x(0);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
312
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
313 for (int i = 0; i < k; i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
314 v[i](n) *= x(1);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
315
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
316 v[k](n) = x(2) * signum (gnew(n));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
317 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
318 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
319
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
320 for (int k = 0; k < nargin; k++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
321 retval(1+k) = v[k];
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
322
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
323 retval (0) = g;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
324 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
325 }
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
326 else if (nargin == 1)
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
327 {
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
328 NDArray gg = args(0).array_value ();
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
329
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
330 int nel = dv.numel ();
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
331
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
332 NDArray v (dv);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
333
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
334 RowVector x (3);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
335 RowVector y (3);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
336
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
337 double g = std::abs (gg(0));
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
338
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
339 if (! is_integer_value (g))
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
340 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
341 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
342 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
343 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
344
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
345 v(0) = signum (gg(0));
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
346
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
347 for (int k = 1; k < nel; k++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
348 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
349 x(0) = g;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
350 x(1) = 1;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
351 x(2) = 0;
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
352
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
353 y(0) = std::abs (gg(k));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
354 y(1) = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
355 y(2) = 1;
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
356
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
357 if (! is_integer_value (y(0)))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
358 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
359 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
360 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
361 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
362
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
363 while (y(0) > 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
364 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
365 RowVector r = x - y * std::floor (x(0) / y(0));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
366 x = y;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
367 y = r;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
368 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
369
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
370 g = x(0);
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
371
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
372 for (int i = 0; i < k; i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
373 v(i) *= x(1);
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
374
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
375 v(k) = x(2) * signum (gg(k));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
376 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
377
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
378 retval (1) = v;
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
379 retval (0) = g;
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
380 }
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
381 else if (all_args_scalar && nargout < 3)
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
382 {
5985
5f662c1cfbbe [project @ 2006-09-12 02:41:46 by jwe]
jwe
parents: 5964
diff changeset
383 double g = args(0).double_value ();
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
384
5985
5f662c1cfbbe [project @ 2006-09-12 02:41:46 by jwe]
jwe
parents: 5964
diff changeset
385 if (error_state || ! is_integer_value (g))
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
386 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
387 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
388 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
389 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
390
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
391 RowVector v (nargin, 0);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
392 RowVector x (3);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
393 RowVector y (3);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
394
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
395 v(0) = signum (g);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
396
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
397 g = std::abs(g);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
398
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
399 for (int k = 1; k < nargin; k++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
400 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
401 x(0) = g;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
402 x(1) = 1;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
403 x(2) = 0;
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
404
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
405 y(0) = args(k).double_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
406 y(1) = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
407 y(2) = 1;
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
408
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
409 double sgn = signum (y(0));
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
410
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
411 y(0) = std::abs (y(0));
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
412
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
413 if (error_state || ! is_integer_value (g))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
414 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
415 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
416 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
417 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
418
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
419 while (y(0) > 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
420 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
421 RowVector r = x - y * std::floor (x(0) / y(0));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
422 x = y;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
423 y = r;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
424 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
425
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
426 g = x(0);
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
427
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
428 for (int i = 0; i < k; i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
429 v(i) *= x(1);
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
430
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
431 v(k) = x(2) * sgn;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
432 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
433
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
434 retval (1) = v;
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
435 retval (0) = g;
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
436 }
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
437 else
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
438 {
5964
3ffedee0aef7 [project @ 2006-08-24 17:33:28 by jwe]
jwe
parents: 5823
diff changeset
439 // FIXME -- we need to handle a possible mixture of scalar and
3ffedee0aef7 [project @ 2006-08-24 17:33:28 by jwe]
jwe
parents: 5823
diff changeset
440 // array values here.
3ffedee0aef7 [project @ 2006-08-24 17:33:28 by jwe]
jwe
parents: 5823
diff changeset
441
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
442 NDArray g = args(0).array_value ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
443
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
444 OCTAVE_LOCAL_BUFFER (NDArray, v, nargin);
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
445
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
446 int nel = dv.numel ();
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
447
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
448 v[0].resize(dv);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
449
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
450 for (int i = 0; i < nel; i++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
451 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
452 v[0](i) = signum (g(i));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
453 g(i) = std::abs (g(i));
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
454
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
455 if (! is_integer_value (g(i)))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
456 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
457 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
458 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
459 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
460 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
461
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
462 RowVector x (3);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
463 RowVector y (3);
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
464
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
465 for (int k = 1; k < nargin; k++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
466 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
467 NDArray gnew = args(k).array_value ();
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
468
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
469 v[k].resize(dv);
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
470
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
471 for (int n = 0; n < nel; n++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
472 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
473 x(0) = g(n);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
474 x(1) = 1;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
475 x(2) = 0;
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
476
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
477 y(0) = std::abs (gnew(n));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
478 y(1) = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
479 y(2) = 1;
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
480
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
481 if (! is_integer_value (y(0)))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
482 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
483 error ("gcd: all arguments must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
484 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
485 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
486
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
487 while (y(0) > 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
488 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
489 RowVector r = x - y * std::floor (x(0) / y(0));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
490 x = y;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
491 y = r;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
492 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
493
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
494 g(n) = x(0);
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
495
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
496 for (int i = 0; i < k; i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
497 v[i](n) *= x(1);
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
498
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
499 v[k](n) = x(2) * signum (gnew(n));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
500 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
501 }
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
502
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
503 for (int k = 0; k < nargin; k++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9167
diff changeset
504 retval(1+k) = v[k];
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
505
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
506 retval (0) = g;
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
507 }
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
508
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
509 return retval;
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
510 }
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
511
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
512 /*
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
513
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
514 %!assert(gcd (200, 300, 50, 35), gcd ([200, 300, 50, 35]))
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
515 %!assert(gcd ([200, 300, 50, 35]), 5);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
516 %!assert(gcd (single(200), single(300), single(50), single(35)), gcd (single([200, 300, 50, 35])))
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
517 %!assert(gcd (single([200, 300, 50, 35])), single(5));
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
518
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
519 %!error <Invalid call to gcd.*> gcd ();
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
520
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
521 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
522 %! s.a = 1;
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
523 %! fail("gcd (s)");
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
524
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
525 */
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
526
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
527 /*
4864
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
528 ;;; Local Variables: ***
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
529 ;;; mode: C++ ***
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
530 ;;; End: ***
d49d761c8c93 [project @ 2004-04-16 16:01:11 by jwe]
jwe
parents:
diff changeset
531 */