Introduced _ecl_big_negate.
authorJuan Jose Garcia Ripoll <jjgarcia@jjgr-2.local>
Thu, 28 Jan 2010 17:14:04 +0000 (18:14 +0100)
committerJuan Jose Garcia Ripoll <jjgarcia@jjgr-2.local>
Thu, 28 Jan 2010 17:14:04 +0000 (18:14 +0100)
src/c/big.d
src/c/big_ll.d
src/c/num_arith.d
src/h/external.h

index ece4fcc..397f33b 100644 (file)
@@ -228,6 +228,15 @@ _ecl_fix_minus_big(cl_fixnum a, cl_object b)
         return big_normalize(z);
 }
 
+cl_object
+_ecl_big_negate(cl_object a)
+{
+        cl_index size_a = (a->big.big_size < 0)? -a->big.big_size : a->big.big_size;
+        cl_object z = _ecl_alloc_compact_bignum(size_a);
+        mpz_neg(z->big.big_num, a->big.big_num);
+        return big_normalize(z);
+}
+
 static void *
 mp_alloc(size_t size)
 {
index a40f890..db8b1b6 100644 (file)
@@ -124,6 +124,14 @@ _ecl_big_plus_fix(cl_object x, cl_fixnum y)
        return big_normalize(z);
 }
 
+cl_object
+_ecl_big_negate(cl_object x)
+{
+       cl_object z = ecl_alloc_object(t_bignum);
+        z->big.big_num = -x->big.big_num;
+       return z;
+}
+
 void
 init_big(void)
 {
index 26fe0c6..0574677 100644 (file)
@@ -711,17 +711,13 @@ ecl_negate(cl_object x)
        case t_fixnum:
                 return ecl_make_integer(-fix(x));
        case t_bignum:
-               z = _ecl_big_register0();
-                _ecl_big_complement(z, x);
-               return _ecl_big_register_normalize(z);
-
+               return _ecl_big_negate(x);
        case t_ratio:
                z1 = ecl_negate(x->ratio.num);
                z = ecl_alloc_object(t_ratio);
                z->ratio.num = z1;
                z->ratio.den = x->ratio.den;
                return z;
-
 #ifdef ECL_SHORT_FLOAT
        case t_shortfloat:
                return make_shortfloat(-ecl_shortfloat(x));
@@ -730,7 +726,6 @@ ecl_negate(cl_object x)
                z = ecl_alloc_object(t_singlefloat);
                sf(z) = -sf(x);
                return z;
-
        case t_doublefloat:
                z = ecl_alloc_object(t_doublefloat);
                df(z) = -df(x);
index 3d3daa8..37f96cb 100755 (executable)
@@ -384,6 +384,7 @@ extern ECL_API cl_object _ecl_big_plus_fix(cl_object x, cl_fixnum y);
 extern ECL_API cl_object _ecl_big_plus_big(cl_object x, cl_object y);
 extern ECL_API cl_object _ecl_fix_minus_big(cl_fixnum x, cl_object y);
 extern ECL_API cl_object _ecl_big_minus_big(cl_object x, cl_object y);
+extern ECL_API cl_object _ecl_big_negate(cl_object x);
 extern ECL_API void _ecl_big_register_free(cl_object x);
 extern ECL_API cl_object bignum1(cl_fixnum val);