* libguile/integers.c (scm_integer_length_i)
(scm_integer_length_z): New internal functions.
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_integer_length): Use new internal functions.
* libguile/integers.h (scm_bignum): Declare opaque struct type and a
function to cast SCM to this type. Adapt all routines that take bignums
to take a "struct scm_bignum *".
* libguile/integers.c: Adapt.
* libguile/numbers.c: Adapt all users.
* libguile/integers.c (scm_integer_logcount_i)
(scm_integer_logcount_z): New internal functions.
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_logcount): Use new internal functions.
* libguile/integers.c (scm_integer_bit_extract_i)
(scm_integer_bit_extract_z): New internal functions.
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_bit_extract): Use new internal functions.
* libguile/integers.c (scm_integer_lsh_iu, scm_integer_lsh_zu)
(scm_integer_floor_rsh_iu, scm_integer_floor_rsh_zu)
(scm_integer_round_rsh_iu, scm_integer_round_rsh_zu): New internal
functions.
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_ash): Use new internal functions.
* libguile/numbers.c (integer_expt_var): New static variable.
(init_integer_expt_var): New helper.
(scm_integer_expt): Delegate to Scheme.
* module/ice-9/boot-9.scm (integer-expt): Reimplement in Scheme. Misses
some optimizations for fractions but that is probably OK!
* libguile/integers.c (scm_integer_modulo_expt_nnn):
(integer_init_mpz): New helper.
* libguile/integers.h: Declare the new internal function.
* libguile/numbers.c (scm_modulo_expt): Use new internal function.
* libguile/integers.c (scm_integer_lognot_i, scm_integer_lognot_z):
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_lognot): Use new internal functions.
* libguile/integers.c (scm_integer_logbit_ui, scm_integer_logbit_uz):
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_logbit_p): Use new internal functions.
* libguile/integers.c (scm_integer_logtest_ii, scm_integer_logtest_zi)
(scm_integer_logtest_zz): New internal functions.
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_logtest): Use new internal functions.
* libguile/integers.c (scm_integer_logxor_ii, scm_integer_logxor_zi)
(scm_integer_logxor_zz): New internal functions.
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_logxor): Use new internal functions.
* libguile/integers.c (scm_integer_logior_ii, scm_integer_logior_zi)
(scm_integer_logior_zz): New internal functions.
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_logior): Use new internal functions.
* libguile/integers.c (scm_integer_logand_ii, scm_integer_logand_zi)
(scm_integer_logand_zz): New internal functions.
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_logand): Use new internal functions.
* libguile/integers.c (scm_integer_lcm_ii)
(scm_integer_lcm_zi, scm_integer_lcm_zz): New internal functions.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_lcm): Use the new functions.
* libguile/integers.c (scm_integer_gcd_ii)
(scm_integer_gcd_zi, scm_integer_gcd_zz): New internal functions.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_gcd): Use the new functions.
* libguile/integers.c (scm_integer_ceiling_remainder_ii)
(scm_integer_ceiling_remainder_iz, scm_integer_ceiling_remainder_zi)
(scm_integer_ceiling_remainder_zz): New internal functions.
(bignum_is_positive): New helper.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_ceiling_remainder): Use the new functions.
* libguile/integers.c (scm_integer_ceiling_quotient_ii)
(scm_integer_ceiling_quotient_iz, scm_integer_ceiling_quotient_zi)
(scm_integer_ceiling_quotient_zz): New internal functions.
(take_bignum_from_mpz): Change to also normalize the mpz, as all callers
required.
(long_sign, bignum_cmp_long): New helpers.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_ceiling_quotient): Use the new functions.
* libguile/integers.c (scm_integer_abs_i, scm_integer_abs_z): New
internal functions.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_abs): Use the new functions.
* libguile/integers.c (scm_is_integer_odd_i):
(scm_is_integer_odd_z): New internal functions. Add a number of
internal support routines.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_odd_p, scm_even_p): Use the new functions.
The goal is to factor out some fixnum/bignum code here from
numbers.[ch].
* libguile/Makefile.am: Add new files.
* libguile/integers.c:
* libguile/integers.h: New files
When heap-numbers-equal? is called from eqv?, we have already ensured
that the both objects have the same heap type. However when called by
the VM, the precondition is just that both are heap numbers -- not
necessarily of the same type. Fix to add an additional check in
heap-numbers-equal?. Could cause crashers!
* libguile/eq.c (scm_i_heap_numbers_equal_p): Add additional check.
This patch removes the undocumented function make-srfi-4-vector from
(guile). That function is still exported from (srfi srfi-4 gnu).
* libguile/srfi-4.h (scm_init_srfi_4): Split into scm_bootstrap_srfi_4()
and scm_init_srfi_4(), after the pattern of scm_init_bytevectors() and
scm_bootstrap_bytevectors().
* libguile/init.c: Replace scm_init_srfi_4() call by scm_bootstrap_srfi_4().
* module/srfi/srfi-4.scm: Load newly defined srfi-4 extension. This
provides undocumented make-srfi-4-vector.
* module/srfi/srfi-4/gnu.scm: Export srfi-4-vector-type-size.
* doc/ref/srfi-modules.texi: Document srfi-4-vector-type-size.
* libguile/foreign.h (SCM_FOREIGN_TYPE_COMPLEX_FLOAT,
SCM_FOREIGN_TYPE_COMPLEX_DOUBLE): New enums.
* module/system/foreign.scm (complex-float, complex-double): Export new types.
(make-c-struct, parse-c-struct): Support the new types.
* libguile/foreign.c (complex-float, complex-double): Define new types.
(alignof, sizeof, pack, unpack): Support the new types.
* test-suite/tests/foreign.test: Test.
This avoids gmp aborting e.g. with (ash 1 (expt 2 37)). The new limit is
such that (ash 1 (expt 30)) is accepted but (ash 1 (expt 31)) throws.
Fixes https://bugs.gnu.org/48150
* libguile/numbers.c (ash, round-ash): As stated.
* test-suite/tests/numbers.test: Test a case known to make gmp abort before.
These use the argument conventions of vector-copy!, string-copy!,
etc. and not that of bytevector-copy! (which is from r6rs).
* module/srfi/srfi-4/gnu.scm: As stated.
* test-suite/tests/srfi-4.test: Tests.
* doc/ref/srfi-modules.texi: Documentation.
* libguile/bytevectors.c (bytevector-copy!): Add overlap note to
docstring.
* libguile/vectors.c (vector-copy!): Reuse text for the overlap note.
* libguile/bytevectors.c (bytevector-fill!): As stated.
(scm_bytevector_fill_x): Stub to avoid changing the C API.
* doc/ref/api-data.texi: Documentation.
* libguile/vectors.c (vector-fill!): Less confusing variable names.
* test-suite/tests/bytevectors.test: Test partial fill cases for
bytevector-fill!.
This flag was set, but never used in Guile, and there was no documented
API to access it.
To check if an array is contiguous, use (array-contents <> #t).
* libguile/arrays.h (scm_i_raw_array): New function.
SCM_I_ARRAY_CONTIGUOUS, SCM_SET_ARRAY_CONTIGUOUS_FLAG,
SCM_CLR_ARRAY_CONTIGUOUS_FLAG, SCM_I_ARRAY_CONTP: Remove.
scm_t_array_dim: Declare here, not in array-handle.h.
SCM_I_ARRAY_NDIM: Shift by one bit since the contp flag isn't there
anymore.
* module/syste/vm/assembler.scm: Match removal of contp flag.
* libguile/arrays.c (scm_i_make_array): Reuse scm_i_raw_array.
(scm_i_ra_set_contp): Remove.
(scm_transpose_array): Don't set or clear the contp flag.
(scm_make_shared_array): Don't set or clear the contp flag.
(scm_make_typed_array): Don't set the contp flag.
* libguile/array-map.c (scm_i_array_rebase): Reuse scm_i_raw_array.
* Deprecate scm_is_simple_vector.
* libguile/vectors.c (scm_vector_elements,
scm_vector_writable_elements): These functions take an array; reword
to make this clear.
* libguile/print.h: Remove reference to 'simple vector'.
* doc/ref/api-data.texi: Remove documentation for scm_is_simple_vector.
Remove references to 'simple vector'.
Fix documentation for scm_vector_elements,
scm_vector_writable_elements.
* test-suite/tests/arrays.test:
* test-suite/tests/vectors.test: Remove references to 'simple vector'.
This is up to 20%-30% faster than the previous versions in (scheme base) or
(srfi srfi-43) that used vector-move-left!/vector-move-right!.
* libguile/vectors.h:
* libguile/vectors.c: As stated.
* doc/ref/api-data.texi (vector-copy!): Document the new function.
(vector-fill!): Document optional arguments.
(vector-copy): Document optional arguments.
* module/scheme/base.scm: Reuse core vector-copy!.
* module/srfi/srfi-43.scm: Reuse core vector-copy!.