#BUGFIX by mawalch
class: Integer
changed: #isPrime
Fix most bad positives in fallback implementation.
--- a/Integer.st Wed Jul 26 12:37:47 2017 +0200
+++ b/Integer.st Wed Jul 26 12:59:50 2017 +0200
@@ -794,6 +794,8 @@
"Modified: / 15.11.1999 / 20:35:20 / cg"
! !
+
+
!Integer class methodsFor:'class initialization'!
initialize
@@ -850,6 +852,7 @@
"Modified: 18.7.1996 / 12:26:38 / cg"
! !
+
!Integer class methodsFor:'prime numbers'!
flushPrimeCache
@@ -1227,6 +1230,7 @@
^ self == Integer
! !
+
!Integer methodsFor:'Compatibility-Dolphin'!
highWord
@@ -1476,6 +1480,7 @@
"
! !
+
!Integer methodsFor:'bcd conversion'!
decodeFromBCD
@@ -4783,6 +4788,7 @@
isPrime
"return true if I am a prime Number.
+ Pre-condition: I am positive.
This is a q&d hack, which may need optimization if heavily used."
|limit firstFewPrimes|
@@ -4819,6 +4825,12 @@
^ PrimeNumberGenerator isPrime:self.
].
+ "/ Not absolutely correct, but was broken much worse before.
+ limit := self sqrt.
+ limit isNaN ifTrue:[
+ DomainError raiseRequestErrorString:'Number too large for current fallback implementation.'.
+ ].
+ limit := limit asInteger.
(firstFewPrimes last+2) to:limit by:2 do:[:i |
(self \\ i) == 0 ifTrue:[ ^ false ].
].
@@ -4831,6 +4843,8 @@
Time millisecondsToRun:[ (1 to:1000000) count:[:n | n isPrime]] 936 with firstFewPrimes (less tests)
Time millisecondsToRun:[ (1 to:1000000) count:[:n | n isPrime]] 343 with primeCache
"
+
+ "Modified (comment): / 26-07-2017 / 12:58:45 / mawalch"
!
nextMultipleOf: n
@@ -4975,6 +4989,7 @@
"Created: / 09-01-2012 / 17:18:06 / cg"
! !
+
!Integer methodsFor:'special modulo arithmetic'!
add_32:anInteger