Greatest common divisor: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 3,053: | Line 3,053: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
===num crate=== |
===num crate=== |
||
<lang |
<lang rust>extern crate num; |
||
use num::integer::gcd;</lang> |
use num::integer::gcd;</lang> |
||
===Iterative Euclid algorithm=== |
===Iterative Euclid algorithm=== |
||
<lang |
<lang rust>fn gcd(mut m: i32, mut n: i32) -> i32 { |
||
while m != 0 { |
while m != 0 { |
||
let old_m = m; |
let old_m = m; |
||
Line 3,067: | Line 3,067: | ||
===Recursive Euclid algorithm=== |
===Recursive Euclid algorithm=== |
||
<lang |
<lang rust>fn gcd(m: i32, n: i32) -> i32 { |
||
if m == 0 { |
if m == 0 { |
||
n.abs() |
n.abs() |
||
Line 3,076: | Line 3,076: | ||
===Tests=== |
===Tests=== |
||
<lang |
<lang rust> |
||
println!("{}",gcd(399,-3999)); |
println!("{}",gcd(399,-3999)); |
||
println!("{}",gcd(0,3999)); |
println!("{}",gcd(0,3999)); |