mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-03-15 17:30:37 -07:00
Fixed and used _ecl_fix_minus_big and _ecl_big_minus_big.
This commit is contained in:
parent
11a1ffb74f
commit
101569dc8f
2 changed files with 9 additions and 31 deletions
18
src/c/big.d
18
src/c/big.d
|
|
@ -220,18 +220,12 @@ _ecl_big_minus_big(cl_object a, cl_object b)
|
|||
cl_object
|
||||
_ecl_fix_minus_big(cl_fixnum a, cl_object b)
|
||||
{
|
||||
cl_object z;
|
||||
if (a == 0) {
|
||||
return ecl_negate(b);
|
||||
} else {
|
||||
cl_index size_b = (b->big.big_size < 0)? -b->big.big_size
|
||||
: b->big.big_size;
|
||||
cl_index size_z = size_b + limbs_per_fixnum;
|
||||
cl_object z = _ecl_alloc_compact_bignum(size_z);
|
||||
mpz_set_si(z->big.big_num, a);
|
||||
mpz_sub(z->big.big_num, z->big.big_num, b->big.big_num);
|
||||
return big_normalize(z);
|
||||
}
|
||||
cl_index size_b = (b->big.big_size < 0)? -b->big.big_size : b->big.big_size;
|
||||
cl_index size_z = size_b + limbs_per_fixnum;
|
||||
cl_object z = _ecl_alloc_compact_bignum(size_z);
|
||||
mpz_set_si(z->big.big_num, a);
|
||||
mpz_sub(z->big.big_num, z->big.big_num, b->big.big_num);
|
||||
return big_normalize(z);
|
||||
}
|
||||
|
||||
static void *
|
||||
|
|
|
|||
|
|
@ -488,14 +488,7 @@ ecl_minus(cl_object x, cl_object y)
|
|||
case t_fixnum:
|
||||
return ecl_make_integer(fix(x) - fix(y));
|
||||
case t_bignum:
|
||||
z = _ecl_big_register0();
|
||||
i = fix(x);
|
||||
if (i > 0)
|
||||
_ecl_big_sub_ui(z, y, i);
|
||||
else
|
||||
_ecl_big_add_ui(z, y, -i);
|
||||
_ecl_big_complement(z, z);
|
||||
return _ecl_big_register_normalize(z);
|
||||
return _ecl_fix_minus_big(fix(x), y);
|
||||
case t_ratio:
|
||||
z = ecl_times(x, y->ratio.den);
|
||||
z = ecl_minus(z, y->ratio.num);
|
||||
|
|
@ -520,18 +513,9 @@ ecl_minus(cl_object x, cl_object y)
|
|||
case t_bignum:
|
||||
switch (type_of(y)) {
|
||||
case t_fixnum:
|
||||
if ((j = fix(y)) == 0)
|
||||
return(x);
|
||||
z = _ecl_big_register0();
|
||||
if (j > 0)
|
||||
_ecl_big_sub_ui(z, x, j);
|
||||
else
|
||||
_ecl_big_add_ui(z, x, -j);
|
||||
return _ecl_big_register_normalize(z);
|
||||
return _ecl_big_plus_fix(x, -fix(y));
|
||||
case t_bignum:
|
||||
z = _ecl_big_register0();
|
||||
_ecl_big_sub(z, x, y);
|
||||
return _ecl_big_register_normalize(z);
|
||||
return _ecl_big_minus_big(x, y);
|
||||
case t_ratio:
|
||||
z = ecl_times(x, y->ratio.den);
|
||||
z = ecl_minus(z, y->ratio.num);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue