29 lines
488 B
Text
29 lines
488 B
Text
|
|
|||
|
/* Integer Math
|
|||
|
*/
|
|||
|
|
|||
|
export {
|
|||
|
/* Euclidean Algorithm to calculate greatest common divisor
|
|||
|
*/
|
|||
|
let gcd = λ{
|
|||
|
a : ℤ ~ machine.Int64;
|
|||
|
b : ℤ ~ machine.Int64;
|
|||
|
} ↦ {
|
|||
|
while( b ) {
|
|||
|
let tmp = i% a b;
|
|||
|
! a b;
|
|||
|
! b tmp;
|
|||
|
}
|
|||
|
a;
|
|||
|
};
|
|||
|
|
|||
|
/* least common multiple
|
|||
|
*/
|
|||
|
let lcm = λ{
|
|||
|
a : ℤ ~ machine.Int64;
|
|||
|
b : ℤ ~ machine.Int64;
|
|||
|
} ↦ i* (int-abs a) (i/ (int-abs b) (gcd a b));
|
|||
|
|
|||
|
};
|
|||
|
|