Remarkable results with psyco and sieve of Eratosthenes
steve at REMOVE.THIS.cybersource.com.au
Thu Nov 30 01:59:58 CET 2006
On Wed, 29 Nov 2006 15:35:39 -0800, Steve Bergman wrote:
> BTW, strictly speaking, shouldn't I be adding something to the floating
> point sqrt result, before converting to int, to allow for rounding
If you don't mind doing no more than one unnecessary test per candidate,
you can just add one to maxfact to allow for that. Or use round()
rather than int(). Or don't convert it at all, just say:
maxfact = math.sqrt(x)
and compare directly to that.
> If it is supposed to be 367 but comes in at 366.99999999, don't
> I potentially classify a composite as a prime?
Do you fear the math.sqrt() function is buggy? If so, all bets are off :-)
> How much needs to be added?
No more than 1, and even that might lead you to sometimes performing an
More information about the Python-list