From b4062b0f9d096388c109b135066bcca901ef1dcd Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 1 Aug 2014 18:50:46 -0500 Subject: factor: catch integer overflow. Now factor 9223372036854775783 (largest positive 64 bit signed prime) takes a couple minutes but gives the right answer. --- toys/other/factor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/toys/other/factor.c b/toys/other/factor.c index e3992a8b..9dc1cca8 100644 --- a/toys/other/factor.c +++ b/toys/other/factor.c @@ -49,7 +49,9 @@ static void factor(char *s) // test odd numbers. for (ll=3; ;ll += 2) { - if (ll*ll>l) { + long lll = ll*ll; + + if (lll>l || lll1) printf(" %ld", l); break; } -- cgit v1.2.3