[Mono-bugs] [Bug 51227][Nor] New - BigInteger.isProbablePrime doesn't work for small integers

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 20 Nov 2003 13:37:30 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by pieter@mentalis.org.

http://bugzilla.ximian.com/show_bug.cgi?id=51227

--- shadow/51227	2003-11-20 13:37:30.000000000 -0500
+++ shadow/51227.tmp.29114	2003-11-20 13:37:30.000000000 -0500
@@ -0,0 +1,38 @@
+Bug#: 51227
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: pieter@mentalis.org               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: BigInteger.isProbablePrime doesn't work for small integers
+
+Description of Problem:
+If you initialize a BigInteger instance with a small prime, 
+isProbablePrime will always return false.
+
+Steps to reproduce the problem:
+1. Create a BigInteger with its value set to a small prime [2, 3, 5, ...]
+2. Call the BigInteger.isProbablePrime method and watch in horror how it 
+returns false
+
+How often does this happen? 
+Always
+
+Additional Information:
+You can fix it by changing the for loop to this:
+    for (int p = 0; p < smallPrimes.Length; p++) {
+        if (this == smallPrimes [p])
+            return true;
+        if (this % smallPrimes [p] == 0)
+            return false;
+    }