PX : code

BCGCD Greatest Common Denominator (Large Numbers) by Sergiu
Download this code


<?php
// The Greatest Common Denominator of two large numbers, using BCMath functions.

// It works even for those who cannot have GMP support in their PHP distribution, for instance due to the web host policy.

// You can see a demo here:
// http://freephpcalculator.tk/
// License: free to do whatever you want with the code
// even using it
function bcgcd ($value1$value2) {
    
    if (
$value1 $value2)
    
// Swap $value1 and $value2
    
{
        
$temp $value1;
        
$value1 $value2;
        
$value2 $temp;
    }

    
// We use the Euclid's algorithm
    // for finding the Greatest Common Denominator (GCD)
    
$mod 1;
    while (
$mod != 0)
    {
        
$mod bcmod ($value1$value2);
        
$value1 $value2;
        
$value2 $mod;
    }
    return 
$value1;

}
?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.