[Ecm-commits] r2612 - trunk

cvs commits ecm-commits at lists.gforge.inria.fr
Sat Feb 14 11:26:39 CET 2015


Author: zimmerma
Date: 2015-02-14 11:26:39 +0100 (Sat, 14 Feb 2015)
New Revision: 2612

Modified:
   trunk/eval.c
   trunk/test.ecm
Log:
more coverage of eval.c


Modified: trunk/eval.c
===================================================================
--- trunk/eval.c	2015-02-13 20:28:32 UTC (rev 2611)
+++ trunk/eval.c	2015-02-14 10:26:39 UTC (rev 2612)
@@ -49,7 +49,6 @@
  *   Phi(x,n)							 *
  *                                                               *
  * NOTE Lines ending in a \ character are "joined"               *
- * NOTE Lines starting with #are comments                        *
  * NOTE C++ // single line comments (rest of line is a comment)  *
  *                                                               *
  ****************************************************************/
@@ -83,11 +82,11 @@
   char *expr = (char *) malloc (nMaxSize + 1);
 
   ASSERT_ALWAYS (expr != NULL);
-JoinLinesLoop:;
+JoinLinesLoop:
   c = fgetc (fd);
-  if (c == '#')
+  if (0)
     {
-ChompLine:;
+ChompLine:
       do
         c = fgetc (fd);
       while (c != EOF && !IS_NEWLINE(c));
@@ -159,7 +158,7 @@
 
   ASSERT_ALWAYS (expr != NULL);
   c = cp;
-JoinLinesLoop:;
+JoinLinesLoop:
   if (*c == '#')
     {
       do
@@ -229,14 +228,15 @@
     mpz_pow_ui(n,prior_n,mpz_get_ui(n));
   else if ('!'==op)	/* simple factorial  (syntax n!    example: 7! == 1*2*3*4*5*6*7) */
     mpz_fac_ui(n,mpz_get_ui(n));
-  else if ('@'==op)	/* Multi factorial   (syntax n at prior_n.  example: 15 at 3 == 15*12*9*6*3) */
+  else if ('@'==op)	/* Multi factorial   (syntax n!prior_n
+                           Example: 15!3 == 15*12*9*6*3
+                           Note: 15!3 is substituted into 15 at 3 by the parser */
     {
       long nCur;
       unsigned long nDecr;
       nCur = mpz_get_si(prior_n);
       nDecr = mpz_get_ui(n);
       mpz_set_ui(n,1);
-      /*printf ("Multi-factorial  %ld!%ld\n", nCur, nDecr);*/
       while (nCur > 1)
 	{
 	  /* This could be done much more efficiently (bunching mults using smaller "built-ins"), but I am not going to bother for now */
@@ -331,55 +331,44 @@
 {
   int factors[200];
   unsigned dwFactors=0, dw;
-  int B;
+  unsigned long B;
   double p;
   mpz_t D, T, org_n;
-
+  
   if (ParamCnt == 0)
-    {
-      fprintf (stderr, "\nParsing Error - the Phi function (in ECM) requires 2 parameters\n");
-      return 0;
-    }
+    return 0;
 
-  if (mpz_cmp_ui(n, 1) == 0)
+  if (mpz_cmp_ui (n, 1) == 0)
     {
       /* return value is 1 if b is composite, or b if b is prime */
       int isPrime = mpz_probab_prime_p (b, PROBAB_PRIME_TESTS);
       if (isPrime)
-	mpz_set(n, b);
+	mpz_set (n, b);
       else
-	mpz_set(n, mpOne);
+	mpz_set (n, mpOne);
       return 1;
     }
-  if (mpz_cmp_si(n, -1) == 0)
-    {
-      /* this is actually INVALID, but it is easier to simply */
-      fprintf (stderr, "\nParsing Error - Invalid parameter passed to the Phi function\n");
-      return 0;
-    }
+  if (mpz_cmp_si (n, -1) == 0)
+    /* this is actually INVALID, but it is easier to simply */
+    return 0;
+
   /* OK parse the Phi out now */
-  if (mpz_cmp_ui(b, 0) == 0)
+  if (mpz_cmp_ui (b, 0) <= 0)
+    return 0;
+
+  if (mpz_cmp_ui (b, 1) == 0)
     {
-      /* this is valid, but return that it is NOT */
-      mpz_set(n, mpOne);
-      return 0;
-    }
-  if (mpz_cmp_ui(b, 1) == 0)
-    {
-      if (mpz_cmp_ui(n, 1) != 0)
-	mpz_sub_ui(n, n, 1);
+      if (mpz_cmp_ui (n, 1) != 0)
+	mpz_sub_ui (n, n, 1);
       return 1;
     }
 
   /* Ok, do the real h_primative work, since we are not one of the trivial case */
 
-  B = mpz_get_si(b);
+  if (mpz_fits_ulong_p (b) == 0)
+    return 0;
 
-  if (mpz_cmp_ui(b, B))
-    {
-      fprintf (stderr, "\nParsing Error - Invalid parameter passed to the Phi function (first param B too high)\n");
-      return 0;
-    }
+  B = mpz_get_ui (b);
 
   /* Obtain the factors of B */
   getprime_clear ();  /* free the prime tables, and reinitialize */
@@ -393,7 +382,7 @@
 	  do { B /= (int) p; } while (B % (int) p == 0);
         }
      }
-  B = mpz_get_si(b);
+  B = mpz_get_si (b);
 
   mpz_init_set(org_n, n);
   mpz_set_ui(n, 1);
@@ -524,9 +513,11 @@
 		      mpz_set(n, t);
 		      if (eval_Phi (n_stack[3], n, 1) == 0)
 			{
-			  mpz_clear(n);
-			  for (i=0;i<4;i++) 
-			    mpz_clear(n_stack[i]);
+                          fprintf (stderr, "\nParsing Error -  Invalid "
+                                   "parameter passed to the Phi function\n");
+			  mpz_clear (n);
+			  for (i = 0; i < 4; i++) 
+			    mpz_clear (n_stack[i]);
 			  return 0;
 			}
 		    }
@@ -565,7 +556,7 @@
    and then fixing the expression up when completed. */
 /* This is ALSO where functions should be sent.  A function should "act" like a stand alone number.
    We should NOT start processing, and expecting a number, but we should expect an operator first */
-MONADIC_SUFFIX_LOOP:;
+MONADIC_SUFFIX_LOOP:
         op=*expr_str++;
 	    
       if (0==op || ')'==op || ']'==op || '}'==op || (','==op&&bInFuncParams))

Modified: trunk/test.ecm
===================================================================
--- trunk/test.ecm	2015-02-13 20:28:32 UTC (rev 2611)
+++ trunk/test.ecm	2015-02-14 10:26:39 UTC (rev 2612)
@@ -126,6 +126,15 @@
 
 echo '101!-1' | $ECM -sigma 0:17 1e5; checkcode $? 2
 
+echo '101!3-1' | $ECM -sigma 0:17 1e5; checkcode $? 2
+
+echo '101#3-2' | $ECM -sigma 0:18 1e5; checkcode $? 14
+
+# parsing error
+echo '2^(101/7)-1' | $ECM -sigma 0:18 1e5; checkcode $? 1
+
+echo "2^1000-(101%7)" | $ECM -sigma 0:17 1e3; checkcode $? 2
+
 # idem with -nobase2
 echo "2^919-1" | $ECM -nobase2 -param 0 -sigma 262763035 937 1; checkcode $? 6
 
@@ -265,10 +274,19 @@
 
 fi
 
-# test to exercise the Phi code in eval.c
+# tests to exercise the Phi code in eval.c
 echo "Phi(101,30)" | $ECM -sigma 0:12023436370081639188 1e5
 checkcode $? 14
 
+echo "1+Phi(102,1)" | $ECM -sigma 0:12023436370081639188 1e5
+checkcode $? 8
+
+echo "Phi(101,1)" | $ECM -sigma 0:12023436370081639188 1e5
+checkcode $? 8
+
+echo "17+Phi(1,2)" | $ECM -sigma 0:17 1e3
+checkcode $? 6
+
 # this example would fail with the old Fgw.c when using gwnum (fixed by David Cleaver, r1734)
 echo "((173^173+1)/174)/471462511391940575680645418941" | $ECM -param 0 -sigma 12345 20000
 checkcode $? 0



More information about the Ecm-commits mailing list