[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 70/85: Fix bug when making mpz from 0
From: |
Andy Wingo |
Subject: |
[Guile-commits] 70/85: Fix bug when making mpz from 0 |
Date: |
Thu, 13 Jan 2022 03:40:25 -0500 (EST) |
wingo pushed a commit to branch main
in repository guile.
commit eac47c3e459ef4441097acf341b72a6fc0ecf172
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Fri Jan 7 22:15:23 2022 +0100
Fix bug when making mpz from 0
* libguile/integers.c (make_bignum_0): New helper.
(make_bignum_from_uint64):
(ulong_to_bignum):
(long_to_bignum): Call new helper as appropriate.
---
libguile/integers.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/libguile/integers.c b/libguile/integers.c
index c7a6e17f8..cc8c2f4fc 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -174,6 +174,12 @@ negate_bignum (struct scm_bignum *z)
return z;
}
+static struct scm_bignum *
+make_bignum_0 (void)
+{
+ return allocate_bignum (0);
+}
+
static struct scm_bignum *
make_bignum_1 (int is_negative, mp_limb_t limb)
{
@@ -200,7 +206,7 @@ make_bignum_from_uint64 (uint64_t val)
if (val > UINT32_MAX)
return make_bignum_2 (0, val, val >> 32);
#endif
- return make_bignum_1 (0, val);
+ return val == 0 ? make_bignum_0 () : make_bignum_1 (0, val);
}
static struct scm_bignum *
@@ -214,7 +220,7 @@ make_bignum_from_int64 (int64_t val)
static struct scm_bignum *
ulong_to_bignum (unsigned long u)
{
- return make_bignum_1 (0, u);
+ return u == 0 ? make_bignum_0 () : make_bignum_1 (0, u);
};
static struct scm_bignum *
@@ -223,7 +229,7 @@ long_to_bignum (long i)
if (i > 0)
return ulong_to_bignum (i);
- return make_bignum_1 (1, long_magnitude (i));
+ return i == 0 ? make_bignum_0 () : make_bignum_1 (1, long_magnitude (i));
};
static inline SCM
- [Guile-commits] 24/85: Implement scm_logtest with new integer library, (continued)
- [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, 2022/01/13
- [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 <=
- [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
- [Guile-commits] 15/85: Implement centered-divide with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 32/85: Integer library takes bignums via opaque struct pointer, Andy Wingo, 2022/01/13
- [Guile-commits] 38/85: Clean up <, reimplement in terms of integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 39/85: positive?, negative? use integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 41/85: Clean up scm_sum, Andy Wingo, 2022/01/13