home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 March / PCWorld_2003-03_cd.bin / Software / Vyzkuste / phptriad / phptriad2-2-1.exe / php / pear / Math / Util.php < prev   
Encoding:
PHP Script  |  2001-11-13  |  1.9 KB  |  59 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2001 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de>               |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Util.php,v 1.3.2.3 2001/11/13 01:26:47 ssb Exp $
  20. //
  21.  
  22. /**
  23.  * Mathematic utilities
  24.  *
  25.  * @author  Sebastian Bergmann <sb@sebastian-bergmann.de>
  26.  * @version $Revision: 1.3.2.3 $
  27.  * @package Numbers
  28.  */
  29. class Math_Util
  30. {
  31.   
  32.     /**
  33.      * Calculates the Greatest Common Divisor (gcd) of two numbers.
  34.      *
  35.      * @param  int a first number
  36.      * @param  int b second number
  37.      * @return int gcd(a,b)
  38.      * @access public
  39.      */
  40.     function gcd($a, $b)
  41.     {
  42.         if ($b > $a) {
  43.             list($a, $b) = array($b, $a);
  44.         }
  45.  
  46.         $c = 1;
  47.  
  48.         // the magic loop (thanks, Euclid :-)
  49.         while ($c > 0) {
  50.             $c = $a % $b;
  51.             $a = $b;
  52.             $b = $c;
  53.         }
  54.  
  55.         return $a;
  56.     }
  57. }
  58. ?>
  59.