Browse Source

FirstD now returns 0 if value can't be found

(Rather than raising an error.)
Petra Lamborn 5 years ago
parent
commit
193fc36d59
1 changed files with 3 additions and 2 deletions
  1. 3
    2
      lucas.py

+ 3
- 2
lucas.py View File

@@ -82,7 +82,8 @@ def Jacobi(a, n):
82 82
 
83 83
 def FirstD(n):
84 84
     """Return first D in the sequence 5, -7, 9, -11, 13, -15... for which the
85
-    Jacobi symbol (D/n) is -1
85
+    Jacobi symbol (D/n) is -1. Returns 0 if the number is a perfect square, or
86
+    otherwise the value can't be found
86 87
     """
87 88
     if n < 1 or n % 2 == 0:
88 89
         raise ValueError("n must be a positive odd number")
@@ -95,7 +96,7 @@ def FirstD(n):
95 96
         # This is supposed to be faster
96 97
         if D > 30 and not haschecked:
97 98
             if hasIntSQRT(n):
98
-                raise ValueError("n must not be a square")
99
+                return 0
99 100
     # Shouldn't fire
100 101
     return 0
101 102