note 13343 deleted from ref.math by cmb

From: Date: Sun, 21 Jul 2019 09:01:00 +0000
Subject: note 13343 deleted from ref.math by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211663@lists.php.net to get a copy of this message
Note Submitter: cornelius at skjoldhoej dot dk ---- I found that when dealing with tables, a 'least common multiple' function is sometimes useful for abusing tablespan and the likes. So here goes (you may choose to remove the first part of the gcd function if the function call is well-behaved): <?php function gcd(n, m) //greatest common divisor { n=abs(n); m=abs(m); if (n==0 and m==0) return 1; //avoid infinite recursion if (n==m and n>=1) return n; return m<n?gcd(n-m,n):gcd(n,m-n); } function lcm(n, m) //least common multiple { return m*(n/gcd(n,m)); } ?> This may or may not be something to consider adding to the mathematical function library.

« previous php.notes (#211663) next »