Moved more uses of _ecl_big_register*() out of sources into big.d. Introduced _ecl_bi...
authorJuan Jose Garcia Ripoll <jjgarcia@jjgr-2.local>
Thu, 28 Jan 2010 22:36:01 +0000 (23:36 +0100)
committerJuan Jose Garcia Ripoll <jjgarcia@jjgr-2.local>
Thu, 28 Jan 2010 22:36:01 +0000 (23:36 +0100)
src/c/big.d
src/c/big_ll.d
src/c/num_arith.d
src/h/external.h
src/h/number.h

index 70e9e49..19187ed 100644 (file)
@@ -273,6 +273,14 @@ _ecl_big_divided_by_big(cl_object a, cl_object b)
 }
 
 cl_object
+_ecl_big_gcd(cl_object a, cl_object b)
+{
+        cl_object z = _ecl_big_register0();
+        mpz_gcd(z->big.big_num, a->big.big_num, b->big.big_num);
+        return _ecl_big_register_normalize(z);
+}
+
+cl_object
 _ecl_big_divided_by_fix(cl_object x, cl_fixnum y)
 {
         ECL_WITH_TEMP_BIGNUM(by, 2);
index e068deb..55d8807 100644 (file)
@@ -66,9 +66,10 @@ _ecl_big_copy(cl_object x)
 }
 
 cl_object
-_ecl_big_gcd(cl_object gcd, cl_object x, cl_object y)
+_ecl_big_gcd(cl_object x, cl_object y)
 {
         big_num_t i = x->big.big_num, j = y->big.big_num;
+        cl_object gcd = ecl_alloc_object(t_bignum);
         while ( 1 ) {
                 big_num_t k;
                 if ( i<j ) {
@@ -78,7 +79,7 @@ _ecl_big_gcd(cl_object gcd, cl_object x, cl_object y)
                 }
                 if ( j == 0 ) {
                         gcd->big.big_num = k;
-                        break;
+                        return gcd;
                 }
                 k = i % j;
                 i = j;
index b190720..6ca058c 100644 (file)
@@ -985,35 +985,29 @@ ecl_integer_divide(cl_object x, cl_object y)
 cl_object
 ecl_gcd(cl_object x, cl_object y)
 {
-       cl_object gcd, x_big, y_big;
+       cl_object gcd;
+        ECL_WITH_TEMP_BIGNUM(x_big,1);
+        ECL_WITH_TEMP_BIGNUM(y_big,1);
 
        switch (type_of(x)) {
        case t_fixnum:
-                x_big = _ecl_big_register0();
                 _ecl_big_set_fixnum(x_big, fix(x));
-               break;
+                x = x_big;
        case t_bignum:
-                x_big = x;
                break;
        default:
                FEtype_error_integer(x);
        }
        switch (type_of(y)) {
        case t_fixnum:
-                y_big = _ecl_big_register1();
                 _ecl_big_set_fixnum(y_big, fix(y));
-                break;
+                y = y_big;
        case t_bignum:
-                y_big = y;
                 break;
        default:
                FEtype_error_integer(y);
         }
-        gcd = _ecl_big_register2();
-        _ecl_big_gcd(gcd, x_big, y_big);
-        if (x != x_big) _ecl_big_register_free(x_big);
-        if (y != y_big) _ecl_big_register_free(y_big);
-        return _ecl_big_register_normalize(gcd);
+        return _ecl_big_gcd(x, y);
 }
 
 /*  (1+ x)  */
index ee18319..422c521 100755 (executable)
@@ -388,6 +388,7 @@ extern ECL_API cl_object _ecl_big_minus_big(cl_object x, cl_object y);
 extern ECL_API cl_object _ecl_fix_divided_by_big(cl_fixnum x, cl_object y);
 extern ECL_API cl_object _ecl_big_divided_by_fix(cl_object x, cl_fixnum y);
 extern ECL_API cl_object _ecl_big_divided_by_big(cl_object x, cl_object y);
+extern ECL_API cl_object _ecl_big_gcd(cl_object x, cl_object y);
 extern ECL_API cl_object _ecl_big_ceiling(cl_object x, cl_object y, cl_object *r);
 extern ECL_API cl_object _ecl_big_floor(cl_object x, cl_object y, cl_object *r);
 extern ECL_API cl_object _ecl_big_negate(cl_object x);
index 6e5d815..2994cba 100644 (file)
@@ -54,7 +54,6 @@ extern ECL_API _ecl_big_set_fixnum(cl_object x, cl_index f);
 #define _ecl_big_tdiv_q(q, x, y)       mpz_tdiv_q((q)->big.big_num,(x)->big.big_num,(y)->big.big_num)
 #define _ecl_big_tdiv_q_ui(q, x, y)    mpz_tdiv_q_ui((q)->big.big_num, (x)->big.big_num, (y))
 #define _ecl_big_set_d(x, d)           mpz_set_d((x)->big.big_num, (d))
-#define _ecl_big_gcd(gcd, x, y)        mpz_gcd((gcd)->big.big_num, (x)->big.big_num, (y)->big.big_num)
 
 #else  /* WITH_GMP */
 
@@ -90,5 +89,4 @@ extern int _ecl_big_num_t_sgn(big_num_t x);
 #define _ecl_big_tdiv_q(q, x, y)       ((q)->big.big_num = (x)->big.big_num / (y)->big.big_num)
 #define _ecl_big_tdiv_q_ui(q, x, y)    ((q)->big.big_num = (x)->big.big_num / (y))
 #define _ecl_big_set_d(x, d)           ((x)->big.big_num = (big_num_t)(d))
-extern ECL_API _ecl_big_gcd(cl_object gcd, cl_object x, cl_object y);
 #endif /* WITH_GMP */