[SCM] Lisaac compiler branch, master, updated. lisaac-0.12-421-gd804dae

ontologiae ontologiae at ordinateur-de-ontologiae.local
Thu Aug 20 19:25:53 UTC 2009


The following commit has been merged in the master branch:
commit 0ebc8ffbd14265f5d76456b7bd23a118c8805f85
Author: ontologiae <ontologiae at ordinateur-de-ontologiae.local>
Date:   Thu Aug 20 21:24:39 2009 +0200

    is_prime function

diff --git a/lib/number/integer.li b/lib/number/integer.li
index 04eeea0..a55e6b6 100644
--- a/lib/number/integer.li
+++ b/lib/number/integer.li
@@ -304,7 +304,25 @@ Section Public
   [
     +? {result == other.gcd self};
   ];
- 
+
+
+  - is_prime : BOOLEAN <-
+  // TRUE if `Self' is prime
+  ( + diviseur : INTEGER;
+    + sqrt_s : INTEGER;
+    + result : BOOLEAN;
+
+    sqrt_s := Self.sqrt;
+    ((Self % 2 = 0) && {Self % 3 = 0}).if_false {
+    result := TRUE;
+    1.to ((sqrt_s+1)/6) until {(Self % diviseur) = 0} do { cpt : INTEGER;
+        diviseur := 6*cpt - ((cpt & 1) << 1) + 1;
+          };
+     result := (diviseur.in_range (sqrt_s -6) to (sqrt_s+6));
+    };
+    result
+  );
+
   //
   // Random
   //

-- 
Lisaac compiler



More information about the Lisaac-commits mailing list