develooper Front page | perl.ppt | Postings from April 2014

factor bug

Thread Next
From:
Dave Nunn
Date:
April 19, 2014 06:44
Subject:
factor bug
Message ID:
CAB6ToBg-+=83tm1V2o0955=_w8VzJL-ST08NpFf-GQbQR8becw@mail.gmail.com
Hello --

Not sure anyone is tracking this, but the factor program at:
http://cpansearch.perl.org/src/CWEST/ppt-0.14/html/commands/factor/factor.feinberg
does indeed have a bug. Try:
factor 3599
and it will report this as prime, though 59*61 == 3599.
The bug is presumably in the line:
$max-- if $max %2;                   # Make the max odd
as this does NOT force $max to be odd, but rather even.
Not sure if the preferred rectification is:
$max++ unless $max %2;
-or-
$max-- unless $max %2;
though either works for the specific case of 3599.

Best wishes,
-- David S. Nunn, PhD
david.s.nunn@gmail.com

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About