[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 59/85: divide2double refactor
From: |
Andy Wingo |
Subject: |
[Guile-commits] 59/85: divide2double refactor |
Date: |
Thu, 13 Jan 2022 03:40:23 -0500 (EST) |
wingo pushed a commit to branch main
in repository guile.
commit 0754dbf3e831ebaadcabf84b3f48012e1c8dbaef
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Fri Jan 7 10:48:31 2022 +0100
divide2double refactor
* libguile/integers.c (scm_integer_set_mpz_z): New internal function.
(scm_integer_init_set_mpz_z): Rename from scm_integer_to_mpz_z.
* libguile/integers.h:
* libguile/numbers.c (scm_i_divide2double): Avoid SCM_I_BIG_MPZ.
---
libguile/integers.c | 11 +++++++++--
libguile/integers.h | 3 ++-
libguile/numbers.c | 17 ++++++++---------
3 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/libguile/integers.c b/libguile/integers.c
index f60173649..f8a03266e 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -3037,14 +3037,21 @@ scm_integer_to_uint64_z (struct scm_bignum *z, uint64_t
*val)
}
void
-scm_integer_to_mpz_z (struct scm_bignum *z, mpz_t n)
+scm_integer_set_mpz_z (struct scm_bignum *z, mpz_t n)
{
mpz_t zn;
alias_bignum_to_mpz (z, zn);
- mpz_init_set (n, zn);
+ mpz_set (n, zn);
scm_remember_upto_here_1 (z);
}
+void
+scm_integer_init_set_mpz_z (struct scm_bignum *z, mpz_t n)
+{
+ mpz_init (n);
+ scm_integer_set_mpz_z (z, n);
+}
+
void
scm_integer_exact_sqrt_i (scm_t_inum k, SCM *s, SCM *r)
{
diff --git a/libguile/integers.h b/libguile/integers.h
index 1d406b659..1acfc1609 100644
--- a/libguile/integers.h
+++ b/libguile/integers.h
@@ -33,7 +33,8 @@ scm_bignum (SCM x)
}
SCM_INTERNAL SCM scm_integer_from_mpz (const mpz_t n);
-SCM_INTERNAL void scm_integer_to_mpz_z (struct scm_bignum *z, mpz_t n);
+SCM_INTERNAL void scm_integer_set_mpz_z (struct scm_bignum *z, mpz_t n);
+SCM_INTERNAL void scm_integer_init_set_mpz_z (struct scm_bignum *z, mpz_t n);
SCM_INTERNAL int scm_is_integer_odd_i (scm_t_inum i);
SCM_INTERNAL int scm_is_integer_odd_z (struct scm_bignum *z);
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 98aff6e1f..9bf85686c 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -443,18 +443,17 @@ scm_i_divide2double (SCM n, SCM d)
mpz_t nn, dd, lo, hi, x;
ssize_t e;
- if (SCM_LIKELY (SCM_I_INUMP (d)))
+ if (SCM_I_INUMP (d))
{
- if (SCM_LIKELY
- (SCM_I_INUMP (n)
- && INUM_LOSSLESSLY_CONVERTIBLE_TO_DOUBLE (SCM_I_INUM (n))
- && INUM_LOSSLESSLY_CONVERTIBLE_TO_DOUBLE (SCM_I_INUM (d))))
+ if (SCM_I_INUMP (n)
+ && INUM_LOSSLESSLY_CONVERTIBLE_TO_DOUBLE (SCM_I_INUM (n))
+ && INUM_LOSSLESSLY_CONVERTIBLE_TO_DOUBLE (SCM_I_INUM (d)))
/* If both N and D can be losslessly converted to doubles, then
we can rely on IEEE floating point to do proper rounding much
faster than we can. */
return ((double) SCM_I_INUM (n)) / ((double) SCM_I_INUM (d));
- if (SCM_UNLIKELY (scm_is_eq (d, SCM_INUM0)))
+ if (scm_is_eq (d, SCM_INUM0))
{
if (scm_is_true (scm_positive_p (n)))
return 1.0 / 0.0;
@@ -467,12 +466,12 @@ scm_i_divide2double (SCM n, SCM d)
mpz_init_set_si (dd, SCM_I_INUM (d));
}
else
- mpz_init_set (dd, SCM_I_BIG_MPZ (d));
+ scm_integer_init_set_mpz_z (scm_bignum (d), dd);
if (SCM_I_INUMP (n))
mpz_init_set_si (nn, SCM_I_INUM (n));
else
- mpz_init_set (nn, SCM_I_BIG_MPZ (n));
+ scm_integer_init_set_mpz_z (scm_bignum (n), nn);
neg = (mpz_sgn (nn) < 0) ^ (mpz_sgn (dd) < 0);
mpz_abs (nn, nn);
@@ -7044,7 +7043,7 @@ scm_to_mpz (SCM val, mpz_t rop)
if (SCM_I_INUMP (val))
mpz_set_si (rop, SCM_I_INUM (val));
else if (SCM_BIGP (val))
- scm_integer_to_mpz_z (scm_bignum (val), rop);
+ scm_integer_set_mpz_z (scm_bignum (val), rop);
else
scm_wrong_type_arg_msg (NULL, 0, val, "exact integer");
}
- [Guile-commits] 69/85: take_mpz optimization, (continued)
- [Guile-commits] 69/85: take_mpz optimization, Andy Wingo, 2022/01/13
- [Guile-commits] 71/85: Re-rewrite integer-expt in C, Andy Wingo, 2022/01/13
- [Guile-commits] 73/85: Optimize scm_integer_mul_zz., Andy Wingo, 2022/01/13
- [Guile-commits] 84/85: Have log and log10(real nan) return real nan regardless of sign, Andy Wingo, 2022/01/13
- [Guile-commits] 85/85: Remove dead code in scm_integer_inexact_sqrt_z, Andy Wingo, 2022/01/13
- [Guile-commits] 24/85: Implement scm_logtest with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 13/85: Implement centered-quotient with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 23/85: Implement scm_logxor with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 19/85: Implement gcd with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 57/85: Expose frexp from integers lib, Andy Wingo, 2022/01/13
- [Guile-commits] 59/85: divide2double refactor,
Andy Wingo <=
- [Guile-commits] 60/85: Simplify scm_exact_integer_quotient, Andy Wingo, 2022/01/13
- [Guile-commits] 61/85: Remove last non-admin SCM_I_BIG_MPZ uses in numbers.c, Andy Wingo, 2022/01/13
- [Guile-commits] 64/85: Avoid scm_i_mkbig outside numbers.c., Andy Wingo, 2022/01/13
- [Guile-commits] 78/85: Optimize bignum subtraction, Andy Wingo, 2022/01/13
- [Guile-commits] 70/85: Fix bug when making mpz from 0, Andy Wingo, 2022/01/13
- [Guile-commits] 83/85: Don't use HAVE_COPYSIGN in libguile/numbers.c, Andy Wingo, 2022/01/13
- [Guile-commits] 20/85: Implement lcm with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 22/85: Implement scm_logior with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 30/85: Implement scm_bit_extract with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 28/85: Reimplement integer-expt in Scheme, Andy Wingo, 2022/01/13