[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 60/69: divide2double refactor
From: |
Andy Wingo |
Subject: |
[Guile-commits] 60/69: divide2double refactor |
Date: |
Fri, 7 Jan 2022 08:27:24 -0500 (EST) |
wingo pushed a commit to branch wip-inline-digits
in repository guile.
commit 45ea295b76f325f5b710188abbbc70a8835dea8a
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] 14/69: Implement centered-quotient with new integer lib, (continued)
- [Guile-commits] 14/69: Implement centered-quotient with new integer lib, Andy Wingo, 2022/01/07
- [Guile-commits] 11/69: Implement truncate-quotient with new integer lib, Andy Wingo, 2022/01/07
- [Guile-commits] 13/69: Implement truncate-divide with new integer lib, Andy Wingo, 2022/01/07
- [Guile-commits] 31/69: Implement scm_bit_extract with new integer library, Andy Wingo, 2022/01/07
- [Guile-commits] 34/69: Implement scm_integer_length with new integer library, Andy Wingo, 2022/01/07
- [Guile-commits] 42/69: Clean up scm_sum, Andy Wingo, 2022/01/07
- [Guile-commits] 43/69: Simplify scm_difference, use integer lib, Andy Wingo, 2022/01/07
- [Guile-commits] 44/69: Simplify scm_product, use integer lib, Andy Wingo, 2022/01/07
- [Guile-commits] 52/69: Reimplement scm_{to,from}_{int64,uint64}, Andy Wingo, 2022/01/07
- [Guile-commits] 53/69: Implement scm_{to,from}_wchar inline, Andy Wingo, 2022/01/07
- [Guile-commits] 60/69: divide2double refactor,
Andy Wingo <=
- [Guile-commits] 65/69: Avoid scm_i_mkbig outside numbers.c., Andy Wingo, 2022/01/07
- [Guile-commits] 57/69: Refactor scm_sqrt in terms of integers.[ch], Andy Wingo, 2022/01/07
- [Guile-commits] 59/69: Remove dead bignum frexp code from numbers.c, Andy Wingo, 2022/01/07
- [Guile-commits] 47/69: Fix deprecated bit-count* when counting 0 bits, Andy Wingo, 2022/01/07
- [Guile-commits] 49/69: Reimplement scm_is_{un, }signed_integer for bignums, Andy Wingo, 2022/01/07
- [Guile-commits] 51/69: Reimplement scm_{to,from}_{int32,uint32}, Andy Wingo, 2022/01/07
- [Guile-commits] 45/69: Remove support for allowing exact numbers to be divided by zero, Andy Wingo, 2022/01/07
- [Guile-commits] 50/69: Reimplement scm_from_int8 etc, Andy Wingo, 2022/01/07
- [Guile-commits] 56/69: Reimplement exact-integer-sqrt with integers.[ch], Andy Wingo, 2022/01/07
- [Guile-commits] 55/69: scm_to_mpz uses integer lib, Andy Wingo, 2022/01/07