[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 52/69: Reimplement scm_{to,from}_{int64,uint64}
From: |
Andy Wingo |
Subject: |
[Guile-commits] 52/69: Reimplement scm_{to,from}_{int64,uint64} |
Date: |
Fri, 7 Jan 2022 08:27:16 -0500 (EST) |
wingo pushed a commit to branch wip-inline-digits
in repository guile.
commit 00572f30da0a81d866570f16944d800a39f64df8
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Thu Jan 6 21:12:50 2022 +0100
Reimplement scm_{to,from}_{int64,uint64}
* libguile/numbers.c (scm_to_int64, scm_from_int64, scm_to_uint64):
(scm_from_uint64): Reimplement inline.
---
libguile/numbers.c | 63 +++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 46 insertions(+), 17 deletions(-)
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 22321ebb2..9ea860600 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -6996,7 +6996,7 @@ scm_to_uint32 (SCM arg)
#if SCM_SIZEOF_LONG == 4
if (SCM_I_INUMP (arg))
{
- if (SCM_I_INUM (arg) > 0)
+ if (SCM_I_INUM (arg) >= 0)
return SCM_I_INUM (arg);
}
else if (SCM_BIGP (arg))
@@ -7027,6 +7027,51 @@ scm_from_uint32 (uint32_t arg)
#endif
}
+int64_t
+scm_to_int64 (SCM arg)
+{
+ if (SCM_I_INUMP (arg))
+ return SCM_I_INUM (arg);
+ else if (!SCM_BIGP (arg))
+ scm_wrong_type_arg_msg (NULL, 0, arg, "exact integer");
+ int64_t ret;
+ if (scm_integer_to_int64_z (scm_bignum (arg), &ret))
+ return ret;
+ range_error (arg, scm_integer_from_int64 (INT64_MIN),
+ scm_integer_from_int64 (INT64_MAX));
+}
+
+SCM
+scm_from_int64 (int64_t arg)
+{
+ return scm_integer_from_int64 (arg);
+}
+
+uint64_t
+scm_to_uint64 (SCM arg)
+{
+ if (SCM_I_INUMP (arg))
+ {
+ if (SCM_I_INUM (arg) >= 0)
+ return SCM_I_INUM (arg);
+ }
+ else if (SCM_BIGP (arg))
+ {
+ uint64_t ret;
+ if (scm_integer_to_uint64_z (scm_bignum (arg), &ret))
+ return ret;
+ }
+ else
+ scm_wrong_type_arg_msg (NULL, 0, arg, "exact integer");
+ range_error (arg, 0, scm_integer_from_uint64 (UINT64_MAX));
+}
+
+SCM
+scm_from_uint64 (uint64_t arg)
+{
+ return scm_integer_from_uint64 (arg);
+}
+
#define TYPE scm_t_wchar
#define TYPE_MIN (int32_t)-1
#define TYPE_MAX (int32_t)0x10ffff
@@ -7035,22 +7080,6 @@ scm_from_uint32 (uint32_t arg)
#define SCM_FROM_TYPE_PROTO(arg) scm_from_wchar (arg)
#include "conv-integer.i.c"
-#define TYPE int64_t
-#define TYPE_MIN INT64_MIN
-#define TYPE_MAX INT64_MAX
-#define SIZEOF_TYPE 8
-#define SCM_TO_TYPE_PROTO(arg) scm_to_int64 (arg)
-#define SCM_FROM_TYPE_PROTO(arg) scm_from_int64 (arg)
-#include "conv-integer.i.c"
-
-#define TYPE uint64_t
-#define TYPE_MIN 0
-#define TYPE_MAX UINT64_MAX
-#define SIZEOF_TYPE 8
-#define SCM_TO_TYPE_PROTO(arg) scm_to_uint64 (arg)
-#define SCM_FROM_TYPE_PROTO(arg) scm_from_uint64 (arg)
-#include "conv-uinteger.i.c"
-
void
scm_to_mpz (SCM val, mpz_t rop)
{
- [Guile-commits] 05/69: Implement floor-quotient with new integer lib, (continued)
- [Guile-commits] 05/69: Implement floor-quotient with new integer lib, Andy Wingo, 2022/01/07
- [Guile-commits] 06/69: Implement floor-remainder with new integer lib, Andy Wingo, 2022/01/07
- [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 <=
- [Guile-commits] 53/69: Implement scm_{to,from}_wchar inline, Andy Wingo, 2022/01/07
- [Guile-commits] 60/69: divide2double refactor, Andy Wingo, 2022/01/07
- [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