1 ## Copyright (C) 1994-2012 John W. Eaton
3 ## This file is part of Octave.
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Mapping Function} {} lcm (@var{x}, @var{y})
21 ## @deftypefnx {Mapping Function} {} lcm (@var{x}, @var{y}, @dots{})
22 ## Compute the least common multiple of @var{x} and @var{y},
23 ## or of the list of all arguments. All elements must be the same size or
25 ## @seealso{factor, gcd}
28 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
29 ## Created: 16 September 1994
32 function l = lcm (varargin)
35 if (common_size (varargin{:}) != 0)
36 error ("lcm: all args must be of the same size or scalar");
37 elseif (! all (cellfun ("isnumeric", varargin)))
38 error ("lcm: all arguments must be numeric");
44 msk = l == 0 & x == 0;
45 l .*= x ./ gcd (l, x);
54 %!assert(lcm (3, 5, 7, 15) == 105);