Author veky
Recipients Ananthakrishnan, lemburg, mark.dickinson, rhettinger, serhiy.storchaka, steven.daprano, stutzbach, veky, vstinner
Date 2020-01-29.02:39:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1580265592.45.0.411354773931.issue39479@roundup.psfhosted.org>
In-reply-to
Content
I agree with Raymond that it's really seldom needed. However, I'd like to point out that the "trivial" implementation might not be so trivial after all: as Steven said, it mishandles (0,0) case. And even Tim fell into that trap, so it can't be said it's easily avoided. I agree that this case doesn't really appear in "real world" tasks, but that's not really an excuse: imagine a factorial that didn't work for 0.

Also, a bit more often used case: seeing the code for lcm of 2 arguments, people might (and do; I've seen it) generalize to 3 or more arguments in a way that seems logical and is often correct, but not always (a*b*c//gcd(a,b,c)).

And one more tidbit: the usual formula for lcm doesn't really work for the case of fraction inputs. I know that currently math.gcd doesn't handle fractions, but it could. It's imaginable that that feature will some day be added (just like pow recently started supporting modular inverses), and then suddenly lcd implementations will silently give the wrong result for fractions.

A smart man;-) once said that the main criteria for inclusion in stdlib is that the function is often needed by users, _and_ it's often implemented wrong. I think lcm doesn't really satisfy the first criterion, but it does satisfy the second.
History
Date User Action Args
2020-01-29 02:39:52vekysetrecipients: + veky, lemburg, rhettinger, mark.dickinson, vstinner, stutzbach, steven.daprano, serhiy.storchaka, Ananthakrishnan
2020-01-29 02:39:52vekysetmessageid: <1580265592.45.0.411354773931.issue39479@roundup.psfhosted.org>
2020-01-29 02:39:52vekylinkissue39479 messages
2020-01-29 02:39:52vekycreate