Open hvds opened 2 years ago
Excellent find. All of the
The other routines typically find a single factor, and removing the trivial (2,3,5) factors first seemed like a good idea. But I see how that can make using it awkward.
Trial factoring is kind of a special case even internally, as we usually want to do trial factoring until we find something, process that, then possibly continue. Currently it uses from,to arguments to allow this, but arguably using context or an iterator would be better.
I'm rewriting the trial factoring code, and will likely choose to have it return all factors up to the given limit.
It's possible that we might want something like trial_factor_one or something that gives exactly one factor, or something like fortrialfactors { ... } $n,$limit
that returns them one by one, and allows early exit with lastfor
.
The docs say it will always return either 1 or 2 numbers:
What it actually returns is a list of any factors of 2, 3 and 5 plus the first trial factor found beyond those, plus any residue; this behaviour is also tested in
t/15-probprime.t
:This doesn't seem like particularly coherent behaviour. I think it should either honour the docs as they stand, or perhaps return all factors up to the trial limit. But whatever the behaviour, the docs should match.
I didn't see any difference in docs or behaviour between the release version and github master.