changeset 32272:b8d5428ed68b

maint: Merge stable to default
author Arun Giridhar <arungiridhar@gmail.com>
date Wed, 23 Aug 2023 19:13:21 -0400
parents f660f76e8058 (current diff) e81b372d1203 (diff)
children 2779eb2ecb74
files
diffstat 2 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/gcd.cc	Wed Aug 23 17:09:29 2023 -0400
+++ b/libinterp/corefcn/gcd.cc	Wed Aug 23 19:13:21 2023 -0400
@@ -473,6 +473,17 @@
 @end group
 @end example
 
+Programming tip: To find the GCD of all the elements of a single array, use
+@code{num2cell} instead of nested calls or a loop:
+
+@example
+@group
+x = [30 42 70 105];    # vector or array of inputs
+gcd (num2cell (x) @{:@})
+   @result{}     1
+@end group
+@end example
+
 @seealso{lcm, factor, isprime}
 @end deftypefn */)
 {
--- a/scripts/specfun/lcm.m	Wed Aug 23 17:09:29 2023 -0400
+++ b/scripts/specfun/lcm.m	Wed Aug 23 19:13:21 2023 -0400
@@ -29,7 +29,30 @@
 ## Compute the least common multiple of @var{x} and @var{y}, or of the list of
 ## all arguments.
 ##
-## All elements must be numeric and of the same size or scalar.
+## All inputs must be of the same size, or scalar.  All elements must be
+## real integer or Gaussian (complex) integer.  For complex inputs, the result
+## is unique only up to a phase factor (multiplication by +1, +i, -1, or -i),
+## and one of the four is returned arbitrarily.
+##
+## Example code:
+##
+## @example
+## @group
+## lcm (5:8, 9:12)
+##    @result{}  45  30  77  24
+## @end group
+## @end example
+##
+## Programming tip: To find the LCM of all the elements of a single array, use
+## @code{num2cell} instead of nested calls or a loop:
+##
+## @example
+## @group
+## x = 1:10;    # vector or array of inputs
+## lcm (num2cell (x) @{:@})
+##    @result{}     2520
+## @end group
+## @end example
 ## @seealso{factor, gcd, isprime}
 ## @end deftypefn