Core typesmath
gcd and lcm
gcd and lcm for int: signs, zero, and the overflow stop.
gcd(a, b) is the greatest common divisor and lcm(a, b) the least common multiple. Both are never negative.
fn main() {
print(math.gcd(12, 18), math.gcd(-12, 18), math.gcd(0, 5), math.gcd(0, 0))
print(math.lcm(4, 6), math.lcm(0, 3), math.lcm(-4, 6))
}6 6 5 0
12 0 12gcd(0, 0)is 0 andgcd(0, n)is|n|.lcm(0, n)is 0.lcmstops witharithmetic overflowwhen the result does not fit in anint:
fn main() {
print(math.lcm(9223372036854775807, 2))
}core.math:124: stopped: arithmetic overflow