note 86931 added to function.gmp-gcd

From: Date: Tue, 11 Nov 2008 03:50:01 +0000
Subject: note 86931 added to function.gmp-gcd
Groups: php.notes 
Request: Send a blank email to php-notes+get-146376@lists.php.net to get a copy of this message
Here's my solution for getting the GCD of several numbers. <?php /* * function gcd() * * returns greatest common divisor * between two numbers * tested against gmp_gcd() */ function gcd($a, $b) { if ($a == 0 || $b == 0) return abs( max(abs($a), abs($b)) ); $r = $a % $b; return ($r != 0) ? gcd($b, $r) : abs($b); } /* * function gcd_array() * * gets greatest common divisor among * an array of numbers */ function gcd_array($array, $a = 0) { $b = array_pop($array); return ($b === null) ? (int)$a : gcd_array($array, gcd($a, $b)); } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 24.176.0.152 ---- Manual Page -- http://www.php.net/manual/en/function.gmp-gcd.php Edit -- https://master.php.net/note/edit/86931 Del: integrated -- https://master.php.net/note/delete/86931/integrated Del: useless -- https://master.php.net/note/delete/86931/useless Del: bad code -- https://master.php.net/note/delete/86931/bad+code Del: spam -- https://master.php.net/note/delete/86931/spam Del: non-english -- https://master.php.net/note/delete/86931/non-english Del: in docs -- https://master.php.net/note/delete/86931/in+docs Del: other reasons-- https://master.php.net/note/delete/86931 Reject -- https://master.php.net/note/reject/86931 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146376) next »