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