lt-core/lt-stdlib/euclidean.lt

28 lines
488 B
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 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));
};