1026
|
1 # Copyright (C) 1995 John W. Eaton |
|
2 # |
|
3 # This file is part of Octave. |
|
4 # |
|
5 # Octave is free software; you can redistribute it and/or modify it |
|
6 # under the terms of the GNU General Public License as published by the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # for more details. |
|
14 # |
|
15 # You should have received a copy of the GNU General Public License |
|
16 # along with Octave; see the file COPYING. If not, write to the Free |
1315
|
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1026
|
18 |
715
|
19 function l = lcm (a, ...) |
904
|
20 |
1026
|
21 # usage: lcm (a, ...) |
|
22 # |
904
|
23 # lcm (a) returns the least common multiple of the entries of the |
|
24 # integer vector a. |
|
25 # lcm (a1, ..., ak) is the same as lcm([a1, ..., ak]). |
715
|
26 |
1026
|
27 # Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Sep 16, 1994. |
715
|
28 |
|
29 if (nargin > 1) |
|
30 va_start; |
904
|
31 for k = 2:nargin; |
|
32 a = [a, va_arg ()]; |
715
|
33 endfor |
|
34 endif |
|
35 |
904
|
36 if (round (a) != a) |
|
37 error ("lcm: all arguments must be integer"); |
715
|
38 endif |
|
39 |
904
|
40 if (any (a) == 0) |
715
|
41 l = 0; |
|
42 else |
904
|
43 a = abs (a); |
|
44 l = a (1); |
|
45 for k = 1:(length (a) - 1) |
1026
|
46 l = l * a(k+1) / gcd (l, a(k+1)); |
715
|
47 endfor |
|
48 endif |
|
49 |
|
50 endfunction |
|
51 |