rust-num / num-integer

Integer trait and functions for Rust
Apache License 2.0
180 stars 48 forks source link

Add new function gcd_lcm for calculating the gcd and lcm simultaneously (performance) #12

Closed haudan closed 5 years ago

haudan commented 6 years ago

Code relying on Integer::gcd and Integer::lcm for identitcal inputs could be sped up by eliminating unecessary recomputations of the gcd. A function computing and returning both could eliminate implicit gcd calls behind the scenes.

// Current situation
let a = 123.gcd(44); // gcd call #1
let b = 123.lcm(44); // gcd call #2, behind the scenes

// PR
// only 1 gcd call in total, which is reused for the lcm computation
let (a, b) = 123.gcd_lcm(44);
haudan commented 6 years ago

Checks failed for Rust 1.20 and below, most likely due to the use of the ..= operator. Should I just use .. instead?

cuviper commented 5 years ago

19 also added gcd_lcm - thanks anyway!