mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
Less pessimal scm_integer_sub_zi
* libguile/integers.c (scm_integer_sub_zi): Only delegate to scm_integer_add_ii if y is negative.
This commit is contained in:
parent
ad6811a12b
commit
2723513712
1 changed files with 16 additions and 4 deletions
|
@ -2875,10 +2875,22 @@ scm_integer_sub_iz (scm_t_inum x, struct scm_bignum *y)
|
||||||
SCM
|
SCM
|
||||||
scm_integer_sub_zi (struct scm_bignum *x, scm_t_inum y)
|
scm_integer_sub_zi (struct scm_bignum *x, scm_t_inum y)
|
||||||
{
|
{
|
||||||
// Assumes that -INUM_MIN can fit in a scm_t_inum, even if that
|
if (y == 0)
|
||||||
// scm_t_inum is not fixable, and that scm_integer_add_ii can handle
|
return scm_from_bignum (x);
|
||||||
// scm_t_inum inputs outside the fixable range.
|
if (y < 0)
|
||||||
return scm_integer_add_zi (x, -y);
|
// Assumes that -INUM_MIN can fit in a scm_t_inum, even if that
|
||||||
|
// scm_t_inum is not fixable, and that scm_integer_add_ii can handle
|
||||||
|
// scm_t_inum inputs outside the fixable range.
|
||||||
|
return scm_integer_add_zi (x, -y);
|
||||||
|
|
||||||
|
mpz_t result, zx;
|
||||||
|
mpz_init (result);
|
||||||
|
alias_bignum_to_mpz (x, zx);
|
||||||
|
mpz_sub_ui (result, zx, y);
|
||||||
|
scm_remember_upto_here_1 (x);
|
||||||
|
// FIXME: We know that if X is negative, no need to check if
|
||||||
|
// result is fixable.
|
||||||
|
return take_mpz (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue