User talk:Spoon!: Difference between revisions

→‎Python/Java infinite generator/iterator error: applies only to fixed types of Java...
(→‎Python/Java infinite generator/iterator error: applies only to fixed types of Java...)
Line 57:
== Python/Java infinite generator/iterator error ==
 
Spoon!, your Java Sieve of Eratosthenes infinite generator [http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Infinite_generatorInfinite_iterator intranslation Pythonto Java] for Python 2.X (using short 32-bit integersint's) andas translated from [http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Infinite_iteratorInfinite_generator theinfinite translationgenerator toin JavaPython] (using 32-bit int's) havehas an overflow problem for finding primes higher than 46,349 as I have noted [http://rosettacode.org/wiki/Talk:Sieve_of_Eratosthenes#Python_translated_to_Java in the Sieve of Eratosthenes Discussion Page]. You should fix this, perhaps by forcing the integer type to long (using the 'L' suffix for Python), although that would break compatibility for the same code between Python 2 and 3 (Python 3 has no 'L' suffix and all integers are that type by default).
 
A better fix would be to postpone the addition of the prime multiple culling sequences to the queue until needed as was done for the dictionary solution (the faster algorithm), in which case the algorithm will work up to the full numeric range of whatever number type is used, including 32-bit integers (2^31 - 1 or 2,147,483,647) otherwise limited to a rage of 46,349. This has the further advantage of much less memory use (by about the ratio of the square root of the memory used) and faster queue re-insertions (a large fraction of the total operations) as these access times are proportional of the log of the queue size, which would then be smaller by the given square root ratio.--[[User:GordonBGood|GordonBGood]] ([[User talk:GordonBGood|talk]]) 0110:0651, 24 June 2014 (UTC)
474

edits