/*------------------------------------------------------------------*/ /* intmath.c (Version 4) */ /* Author: Bob Dondero */ /*------------------------------------------------------------------*/ #include "intmath.h" #include /*------------------------------------------------------------------*/ int IntMath_gcd(int iFirst, int iSecond) /* Return the greatest common divisor of iFirst and iSecond. It is a checked runtime error for iFirst or iSecond to be negative or zero. */ { int iTemp; assert(iFirst > 0); assert(iSecond > 0); while (iSecond != 0) { iTemp = iFirst % iSecond; iFirst = iSecond; iSecond = iTemp; } return iFirst; } /*------------------------------------------------------------------*/ int IntMath_lcm(int iFirst, int iSecond) /* Return the least common multiple of iFirst and iSecond. It is a checked runtime error for iFirst or iSecond to be negative or zero. */ { assert(iFirst > 0); assert(iSecond > 0); return (iFirst / IntMath_gcd(iFirst, iSecond)) * iSecond; }