# lcm(0,n) gives 0 which should be changed. Classic List Threaded 5 messages Open this post in threaded view
|

## lcm(0,n) gives 0 which should be changed.

 In MATLAB, >> lcm(0,1) Error using lcm (line 16) Input arguments must contain positive integers.   >> lcm(0,11) Error using lcm (line 16) Input arguments must contain positive integers. So, MATLAB chooses to make produce error for other numbers than Integer. In Octave, >> lcm(0,1) ans = 0 >> lcm(0,10) ans = 0 So Octave gives lcm(0,n) 0. So like this any number x,y should produce lcm to be 0. lcm(x,y) = 0 will be always true in this sense. And lcm(x,y) is divisible by both x and y but we know 0/0 undefined or NaN(Octave uses). Please correct me so that I can learn. -- Sent from: http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html
Open this post in threaded view
|

## Re: lcm(0,n) gives 0 which should be changed.

 On Sat, 2018-03-24 at 10:29 -0700, Dildar Sk wrote: > > > lcm(0,10) > > ans = 0 I don't think this is an error and I think Matlab is being excessively restrictive. 0 is indeed the least common multiple of 0 and 10, since you can multiply 0 and 10 by something and get 0, and 0 is the smallest number that can be a multiple of both. I suppose you can argue that 0 is always the lcm of any two nonnegative integers and the output of lcm should positive to rule out 0. I think it makes more sense to return something here since one of the inputs is zero, instead of erroring out. In general, Matlab considering some inputs to be an error when Octave does not is acceptable. For example, Octave can handle the Gaussian integers:     gcd (7+6i, 6-2i)     ans = -1 + 2i I belive Matlab does not accept complex arguments for gcd.
Open this post in threaded view
|

## Re: lcm(0,n) gives 0 which should be changed.

 Jordi Gutiérrez Hermoso-2 wrote > I suppose you can argue that 0 is always the lcm of any two > nonnegative integers and the output of lcm should positive to rule out > 0. I think it makes more sense to return something here since one of > the inputs is zero, instead of erroring out. Forgive me, but lcm of x,y lcm(x,y) must be divisible by x and y. But if lcm(0,n) produces 0 that means 0 is divisible by 0.But 0/0 is undefined. -- Sent from: http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html