[libmath-prime-util-perl] 02/35: Add XS routine for ([p1, p2, p3], [e1, e2, e3]) return from factor

Partha P. Mukherjee ppm-guest at moszumanska.debian.org
Thu May 21 18:50:01 UTC 2015


This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.33
in repository libmath-prime-util-perl.

commit ab0a8697b107247fd82bcfc33ba24d7710ee3c64
Author: Dana Jacobsen <dana at acm.org>
Date:   Thu Oct 17 18:33:58 2013 -0700

    Add XS routine for ([p1,p2,p3],[e1,e2,e3]) return from factor
---
 XS.xs | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/XS.xs b/XS.xs
index 3cf76a5..4d341d3 100644
--- a/XS.xs
+++ b/XS.xs
@@ -409,6 +409,42 @@ _XS_factor(IN UV n)
     }
 
 void
+_XS_factor_exp(IN UV n)
+  PREINIT:
+    UV factors[MPU_MAX_FACTORS+1];
+    int i, j, nfactors;
+  PPCODE:
+    nfactors = factor(n, factors);
+    if (GIMME_V == G_SCALAR) {
+      /* Count unique prime factors and return the scalar */
+      for (i = 1, j = 1; i < nfactors; i++)
+        if (factors[i] != factors[i-1])
+          j++;
+      PUSHs(sv_2mortal(newSVuv(j)));
+    } else {
+      /* Return ( [p1, p2, p3, ...],  [e1, e2, e3, ...] ) */
+      UV exponents[MPU_MAX_FACTORS+1];
+      AV* fav = newAV();
+      AV* eav = newAV();
+      exponents[0] = 1;
+      for (i = 1, j = 1; i < nfactors; i++) {
+        if (factors[i] != factors[i-1]) {
+          exponents[j] = 1;
+          factors[j++] = factors[i];
+        } else {
+          exponents[j-1]++;
+        }
+      }
+      nfactors = j;
+      for (i = 0; i < nfactors; i++) {
+        av_push(fav, newSVuv(factors[i]));
+        av_push(eav, newSVuv(exponents[i]));
+      }
+      XPUSHs( sv_2mortal(newRV_noinc( (SV*) fav )) );
+      XPUSHs( sv_2mortal(newRV_noinc( (SV*) eav )) );
+    }
+
+void
 trial_factor(IN UV n, IN UV maxfactor = 0)
   PPCODE:
     SIMPLE_FACTOR(trial_factor, n, maxfactor);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git



More information about the Pkg-perl-cvs-commits mailing list