[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 36/85: Build scm_integer_p on scm_is_integer, not vice v
From: |
Andy Wingo |
Subject: |
[Guile-commits] 36/85: Build scm_integer_p on scm_is_integer, not vice versa |
Date: |
Thu, 13 Jan 2022 03:40:19 -0500 (EST) |
wingo pushed a commit to branch main
in repository guile.
commit ef5ade30f91093d2bb8be9e4ca457d4da53ee408
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Tue Jan 4 12:01:18 2022 +0100
Build scm_integer_p on scm_is_integer, not vice versa
* libguile/numbers.c: Switch layering of scm_is_integer /
scm_is_exact_integer and their SCM-valued counterparts.
---
libguile/numbers.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 51e5ee19a..46f55de58 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -4605,15 +4605,7 @@ SCM_DEFINE (scm_integer_p, "integer?", 1, 0, 0,
"else return @code{#f}.")
#define FUNC_NAME s_scm_integer_p
{
- if (SCM_I_INUMP (x) || SCM_BIGP (x))
- return SCM_BOOL_T;
- else if (SCM_REALP (x))
- {
- double val = SCM_REAL_VALUE (x);
- return scm_from_bool (!isinf (val) && (val == floor (val)));
- }
- else
- return SCM_BOOL_F;
+ return scm_from_bool (scm_is_integer (x));
}
#undef FUNC_NAME
@@ -4623,10 +4615,7 @@ SCM_DEFINE (scm_exact_integer_p, "exact-integer?", 1, 0,
0,
"else return @code{#f}.")
#define FUNC_NAME s_scm_exact_integer_p
{
- if (SCM_I_INUMP (x) || SCM_BIGP (x))
- return SCM_BOOL_T;
- else
- return SCM_BOOL_F;
+ return scm_from_bool (scm_is_exact_integer (x));
}
#undef FUNC_NAME
@@ -7716,13 +7705,20 @@ SCM_DEFINE (scm_rationalize, "rationalize", 2, 0, 0,
int
scm_is_integer (SCM val)
{
- return scm_is_true (scm_integer_p (val));
+ if (scm_is_exact_integer (val))
+ return 1;
+ if (SCM_REALP (val))
+ {
+ double x = SCM_REAL_VALUE (val);
+ return !isinf (x) && (x == floor (x));
+ }
+ return 0;
}
int
scm_is_exact_integer (SCM val)
{
- return scm_is_true (scm_exact_integer_p (val));
+ return SCM_I_INUMP (val) || SCM_BIGP (val);
}
int
- [Guile-commits] 25/85: Implement scm_logbit_p with new integer library, (continued)
- [Guile-commits] 25/85: Implement scm_logbit_p with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 14/85: Implement centered-remainder with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 10/85: Implement truncate-quotient with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 26/85: Implement scm_lognot with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 12/85: Implement truncate-divide with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 29/85: Implement scm_ash with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 31/85: Implement scm_logcount with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 33/85: Implement scm_integer_length with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 35/85: Simplify scm_bigprint, Andy Wingo, 2022/01/13
- [Guile-commits] 34/85: Implement integer-to-string with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 36/85: Build scm_integer_p on scm_is_integer, not vice versa,
Andy Wingo <=
- [Guile-commits] 37/85: Reimplement = on integer lib, clean up scm_num_eq_p, Andy Wingo, 2022/01/13
- [Guile-commits] 40/85: Simplify implementation of min, max, Andy Wingo, 2022/01/13
- [Guile-commits] 42/85: Simplify scm_difference, use integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 47/85: Fix scm_integer_to_double_z to always round; clean ups, Andy Wingo, 2022/01/13
- [Guile-commits] 50/85: Reimplement scm_{to,from}_{int32,uint32}, Andy Wingo, 2022/01/13
- [Guile-commits] 67/85: scm_to_ipv6 uses scm_to_mpz, Andy Wingo, 2022/01/13
- [Guile-commits] 68/85: Bignums avoid both custom GMP allocator and finalizers, Andy Wingo, 2022/01/13
- [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