in reply to greatest common factor
I found this function and it seemed reasonable, but some of my users reported that I was somtimes returning the wrong sign.
Turns out that the function above has inconsistent behavior on negative numbers:
when they should really both be 5.gcf(-5, 5) = 5 gcf(5, -5) = -5
14 years late, but here's a fix. I changed my code so that gcf() ends with
return abs $x;
|
---|
In Section
Cool Uses for Perl