Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: greatest common factor

by TheAmigo (Initiate)
on Apr 16, 2015 at 19:51 UTC ( #1123659=note: print w/replies, xml ) Need Help??


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:

gcf(-5, 5) = 5 gcf(5, -5) = -5

when they should really both be 5.

14 years late, but here's a fix. I changed my code so that gcf() ends with

return abs $x;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1123659]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2021-12-05 07:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (31 votes). Check out past polls.

    Notices?