note 36321 added to ref.math

From: Date: Sun, 05 Oct 2003 08:00:46 +0000
Subject: note 36321 added to ref.math
Groups: php.notes 
Request: Send a blank email to php-notes+get-57829@lists.php.net to get a copy of this message
Here's yet another greatest common denominator (gcd) function, a reeeeally small one. function gcd($n,$m){ if(!$m)return$n;return gcd($m,$n%$m); } It works by recursion. Not really sure about it's speed, but it's really small! This won't work on floating point numbers accurately though. If you want a floating point one, you need to have at least PHP 4, and the code would be function gcd($n,$m){ if(!$m)return$n;return gcd($m,fmod($n,$m)); } ---- Manual Page -- http://www.php.net/manual/en/ref.math.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36321 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36321&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36321&report=yes Search Tool -- http://master.php.net/manage/user-notes.php

« previous php.notes (#57829) next »