summaryrefslogtreecommitdiff
path: root/libguile
AgeCommit message (Collapse)AuthorFilesLines
2022-02-05'string->symbol' avoids copying the underlying string.Ludovic Courtès1-3/+7
* libguile/strings.c (scm_i_make_symbol): Reuse NAME's stringbuf unless it's mutable or NAME starts at a non-zero offset.
2022-02-04Deprecate symbol properties.Ludovic Courtès6-68/+76
* libguile/strings.c (scm_i_make_symbol): Remove 'props' argument. Use 3 words instead of 'scm_double_cell'. * libguile/strings.h: Adjust accordingly. * libguile/symbols.c (scm_i_str2symbol, scm_i_str2uninterned_symbol): Likewise. (scm_symbol_fref, scm_symbol_pref, scm_symbol_fset_x, scm_symbol_pset_x): Move to... * libguile/deprecated.c: ... here. Rewrite in terms of object properties. (symbol_function_slot, symbol_property_slot): New variables. * libguile/symbols.h (SCM_SYMBOL_FUNC, SCM_SET_SYMBOL_FUNC) (SCM_SYMBOL_PROPS, SCM_SET_SYMBOL_PROPS) (scm_symbol_fref, scm_symbol_pref, scm_symbol_fset_x) (scm_symbol_pset_x): Move to... * libguile/deprecated.h: ... here. Mark declarations as 'SCM_DEPRECATED'. * module/system/base/types.scm (cell->object): Remove 'props' field for %TC7-SYMBOL. * doc/ref/api-data.texi (Symbol Props): Remove. * NEWS: Update.
2022-02-03Remove unused 'scm_i_c_make_symbol'.Ludovic Courtès2-14/+0
* libguile/strings.c (scm_i_c_make_symbol): Remove. * libguile/strings.h (scm_i_c_make_symbol): Remove declaration.
2022-02-01Slight bignum-fixnum multiplication optimizationAndy Wingo1-4/+8
* libguile/integers.c (scm_integer_mul_zi): Use mpn_mul_1.
2022-01-13Remove dead code in scm_integer_inexact_sqrt_zAndy Wingo1-4/+0
* libguile/integers.c (scm_integer_inexact_sqrt_z): Remove some dead code.
2022-01-13Have log and log10(real nan) return real nan regardless of signDaniel Llorens1-8/+9
* libguile/numbers.c (log_of_shifted_double, scm_log10): Avoid complex extension when the argument is a real nan. * test-suite/tests/numbers.test: Tests for nans of either sign.
2022-01-13Don't use HAVE_COPYSIGN in libguile/numbers.cDaniel Llorens1-4/+0
* libguile/numbers.c (icmplx2str): As stated. copysign() is required by C99 and already used without guards elsewhere in this file.
2022-01-13Simplify scm_abs for the real caseDaniel Llorens1-11/+1
* libguile/numbers.c (scm_abs): As stated. When x is a nan with the sign bit set, this changes the behavior of (magnitude x) back to what it was in 3.0.7, to clear that bit.
2022-01-13Optimize logand against a positive inumAndy Wingo1-0/+12
* libguile/integers.c (scm_integer_logand_zi): Optimize.
2022-01-13Optimize integer-expt for fixnumsAndy Wingo1-0/+21
* libguile/integers.c (scm_integer_expt_ii): Add some optimizations for cases in which we can avoid allocating an mpz.
2022-01-13Optimize scm_integer_mul_iiAndy Wingo1-11/+17
* libguile/integers.c (make_bignum_2): Always include. (scm_integer_mul_ii): Avoid making a temporary allocation.
2022-01-13Optimize bignum subtractionAndy Wingo1-29/+47
* libguile/integers.c (scm_integer_sub_iz): (scm_integer_sub_zi): (scm_integer_sub_zz): Optimize to avoid temporary allocations.
2022-01-13Optimize bignum add to avoid temporary allocationsAndy Wingo1-26/+106
* libguile/integers.c (do_add_1, do_add, do_sub_1, do_sub, do_cmp): New helpers. (scm_integer_add_zi): (scm_integer_add_zz): Use new helpers.
2022-01-13Avoid bignum clone in scm_integer_sub_zzAndy Wingo1-2/+10
* libguile/integers.c (scm_integer_abs_z): Just call scm_integer_negate_z if negation is needed. (scm_integer_sub_zz): Use mpz_sub instead of cloning bignum.
2022-01-13Start to optimize scm_integer_sub_izAndy Wingo1-1/+13
* libguile/integers.c (scm_integer_sub_iz): Avoid cloning bignum.
2022-01-13Less pessimal scm_integer_sub_ziAndy Wingo1-4/+16
* libguile/integers.c (scm_integer_sub_zi): Only delegate to scm_integer_add_ii if y is negative.
2022-01-13Optimize scm_integer_mul_zz.Andy Wingo1-6/+18
* libguile/integers.c (scm_integer_mul_zz): Optimize to avoid temporary allocations.
2022-01-13Optimize scm_integer_mul_ziAndy Wingo1-5/+25
* libguile/integers.c (bignum_trim1): (bignum_negate_if): New helpers. (scm_integer_mul_zi): Use the mpn API to avoid temporary allocation.
2022-01-13Re-rewrite integer-expt in CAndy Wingo3-13/+134
Calling out to Scheme was a performance regression. * libguile/integers.h: * libguile/integers.c (scm_integer_expt_ii, scm_integer_expt_zi): New internal functions. * libguile/numbers.c (scm_integer_expt): Go back to C. But, include fast cases for inums and doubles. * module/ice-9/boot-9.scm: Revert addition of integer-expt.
2022-01-13Fix bug when making mpz from 0Andy Wingo1-3/+9
* libguile/integers.c (make_bignum_0): New helper. (make_bignum_from_uint64): (ulong_to_bignum): (long_to_bignum): Call new helper as appropriate.
2022-01-13take_mpz optimizationAndy Wingo1-2/+6
* libguile/integers.c (take_mpz): Avoid making a bignum if the value is fixable.
2022-01-13Bignums avoid both custom GMP allocator and finalizersAndy Wingo4-183/+111
* libguile/deprecated.c (make_bignum): Move here from numbers.c, to support scm_i_long2big etc. (scm_i_big2dbl): (scm_i_long2big): (scm_i_ulong2big): (scm_i_clonebig): (scm_i_normbig): Deprecate. (scm_install_gmp_memory_functions): Deprecate, happily! SCM bignums now have digits allocated inline with the bignum itself, so they are completely transparent to the GC already. The price is that if GMP ever allocates digits via the MPZ API, those digits then have to be copied back into managed memory. But we avoid having to install finalizers and we avoid having to muck with GMP's allocator. * libguile/numbers.c (scm_from_mpz): Use scm_integer_from_mpz. (scm_init_numbers): Never muck with GMP's allocators. * doc/ref/guile-invoke.texi (Environment Variables): Remove note about GUILE_INSTALL_GMP_MEMORY_FUNCTIONS. * meta/build-env.in: No need to set GUILE_INSTALL_GMP_MEMORY_FUNCTIONS.
2022-01-13scm_to_ipv6 uses scm_to_mpzAndy Wingo1-5/+11
* libguile/socket.c (scm_to_ipv6): Use scm_to_mpz.
2022-01-13Finish srfi-60 port off old scm mpz APIAndy Wingo1-77/+72
* libguile/srfi-60.c (scm_srfi60_rotate_bit_field) (scm_srfi60_reverse_bit_field, scm_srfi60_integer_to_list) (scm_srfi60_list_to_integer): Update.
2022-01-13Start porting srfi-60 off the bad bignum interfacesAndy Wingo3-48/+31
* libguile/integers.h: * libguile/integers.c (scm_integer_scan1_i): (scm_integer_scan1_z): New internal functions. * libguile/srfi-60.c (scm_srfi60_log2_binary_factors): Use scan1 functions. (scm_srfi60_copy_bit): Use integers lib.
2022-01-13Avoid scm_i_mkbig outside numbers.c.Andy Wingo4-22/+21
* libguile/random.c (scm_c_random_bignum): * libguile/socket.c (scm_from_ipv6): Avoid scm_i_mkbig. * libguile/numbers.h: * libguile/numbers.c (scm_i_mkbig): Remove.
2022-01-13Use scm_integer_to_double_z in numbers.c instead of big2dblAndy Wingo1-21/+22
* libguile/numbers.c: Use internal function instead of big2dbl which we will deprecate.
2022-01-13Simplify magnitude, angleAndy Wingo1-67/+12
* libguile/numbers.c (scm_i_inum2big): Remove. (scm_magnitude): Delegate to abs. (scm_angle): Simplify.
2022-01-13Remove last non-admin SCM_I_BIG_MPZ uses in numbers.cAndy Wingo1-8/+4
* libguile/numbers.c (scm_magnitude, scm_angle): Use integers lib.
2022-01-13Simplify scm_exact_integer_quotientAndy Wingo3-74/+44
* libguile/integers.h: * libguile/integers.c (scm_integer_exact_quotient_iz): New internal function. * libguile/numbers.c (scm_i_make_ratio): Simplify and enforce invariants. (scm_exact_integer_quotient): Use integer lib.
2022-01-13divide2double refactorAndy Wingo3-12/+19
* 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.
2022-01-13Remove dead bignum frexp code from numbers.cAndy Wingo1-46/+0
* libguile/numbers.c (scm_i_big2dbl_2exp): Remove unused function.
2022-01-13Expose frexp from integers libAndy Wingo3-6/+7
* libguile/integers.h: * libguile/integers.c (scm_integer_frexp_z): Expose internally. (scm_integer_to_double_z): (scm_integer_inexact_sqrt_z): Adapt uses. * libguile/numbers.c (log_of_exact_integer): Use exposed scm_integer_frexp_z.
2022-01-13Refactor scm_sqrt in terms of integers.[ch]Andy Wingo3-153/+130
* libguile/integers.h: * libguile/integers.c (scm_is_integer_perfect_square_i): (scm_is_integer_perfect_square_z): (scm_integer_floor_sqrt_i): (scm_integer_floor_sqrt_z): (scm_integer_inexact_sqrt_i): (scm_integer_inexact_sqrt_z): New internal functions. * libguile/numbers.c (scm_sqrt): Reimplement.
2022-01-13Reimplement exact-integer-sqrt with integers.[ch]Andy Wingo3-31/+44
* libguile/numbers.c (scm_exact_integer_sqrt): Call out. * libguile/integers.h: * libguile/integers.c (scm_integer_exact_sqrt_i): (scm_integer_exact_sqrt_z): New internal functions.
2022-01-13scm_to_mpz uses integer libAndy Wingo3-2/+12
* libguile/integers.h: * libguile/integers.c (scm_integer_to_mpz_z): New internal function. * libguile/numbers.c (scm_to_mpz): Use new function.
2022-01-13Remove unused conv-{u,}integer.i.cAndy Wingo3-272/+2
* libguile/Makefile.am (noinst_HEADERS): * libguile/conv-integer.i.c: * libguile/conv-uinteger.i.c: Remove.
2022-01-13Implement scm_{to,from}_wchar inlineAndy Wingo1-7/+11
* libguile/numbers.c (scm_to_wchar, scm_from_wchar): Implement inline.
2022-01-13Reimplement scm_{to,from}_{int64,uint64}Andy Wingo1-17/+46
* libguile/numbers.c (scm_to_int64, scm_from_int64, scm_to_uint64): (scm_from_uint64): Reimplement inline.
2022-01-13Reimplement scm_{to,from}_{int32,uint32}Andy Wingo3-25/+171
* libguile/numbers.c (scm_to_int32, scm_from_int32, scm_to_uint32): (scm_from_uint32): Reimplement inline. * libguile/integers.c (make_bignum_2): (make_bignum_from_uint64): (negative_uint32_to_int32): (positive_uint32_to_int32): (bignum_to_int32): (bignum_to_uint32): (scm_integer_from_int32): (scm_integer_from_uint32): (scm_integer_to_int32_z): (scm_integer_to_uint32_z): Better int32 support for 32-bit machines.
2022-01-13Reimplement scm_from_int8 etcAndy Wingo3-43/+158
* libguile/integers.c (make_bignum_from_uint64): (make_bignum_from_int64): New helpers. (scm_integer_from_int64): (scm_integer_from_uint64): New internal functions. * libguile/integers.h: Declare new internal functions. * libguile/numbers.c (range_error): Declare as noreturn.xo (inum_in_range): New helper. (scm_from_signed_integer): (scm_to_signed_integer): (scm_from_unsigned_integer): (scm_to_unsigned_integer): (scm_to_int8): (scm_from_int8): (scm_to_uint8): (scm_from_uint8): (scm_to_int16): (scm_from_int16): (scm_to_uint16): (scm_from_uint16): Implement manually.
2022-01-13Reimplement scm_is_{un,}signed_integer for bignumsAndy Wingo3-74/+120
* libguile/integers.c (negative_int64): (int64_magnitude): (negative_uint64_to_int64): (positive_uint64_to_int64): (bignum_to_int64): (bignum_to_uint64): New helpers. (scm_integer_to_int64_z): (scm_integer_to_uint64_z): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_is_signed_integer): (scm_is_unsigned_integer): Simplify bigint cases.
2022-01-13Fix scm_integer_to_double_z to always round; clean upsAndy Wingo5-103/+110
* libguile/integers.c (scm_integer_to_double_z): Doubles that can't be exactly represented as integers should round. (bignum_frexp_z): New helper. (scm_integer_from_mpz, scm_integer_from_double): New internal functions. * libguile/numbers.h: * libguile/numbers.c (scm_i_bigcmp, scm_i_dbl2big, scm_i_dbl2num): Remove unused internal functions. (scm_inexact_to_exact): Rework to avoid scm_i_dbl2big. (scm_bigequal): Move here, from eq.c. (scm_integer_to_double_z): Use the new helper. (scm_i_big2dbl): Use scm_integer_to_double_z.
2022-01-13Fix deprecated bit-count* when counting 0 bitsAndy Wingo1-2/+2
* libguile/deprecated.c (scm_bit_count_star): Fix logic to count 0 bits.
2022-01-13Clean up scm_divideAndy Wingo3-223/+252
* libguile/integers.h: * libguile/integers.c (scm_is_integer_divisible_ii): (scm_is_integer_divisible_zi): (scm_is_integer_divisible_zz): New helpers. * libguile/numbers.c (invert, divide, complex_div): New helpers for scm_divide. (scm_divide): Adapt.
2022-01-13Remove support for allowing exact numbers to be divided by zeroAndy Wingo1-102/+18
* libguile/numbers.c: We require IEEE infinities and NaN so there is no case in which ALLOW_DIVIDE_BY_ZERO would not be defined. (scm_divide, scm_tan, scm_tanh, scm_log, scm_log10): Always throw on overflow for divide by exact zero, never throw for divide by inexact zero.
2022-01-13Simplify scm_product, use integer libAndy Wingo3-189/+147
* libguile/numbers.c (scm_product): Remove need for s_product defines. Call out to product, as appropriate. (product): New helper. * libguile/integers.h: * libguile/integers.c (scm_integer_mul_ii): (scm_integer_mul_zi): (scm_integer_mul_zz): New internal functions.
2022-01-13Simplify scm_difference, use integer libAndy Wingo3-233/+174
* libguile/numbers.c (scm_sum): Remove need for s_sum defines. (negate, difference): New helpers. (scm_difference): Call out to difference or negate, as appropriate. * libguile/integers.h: * libguile/integers.c (scm_integer_negate_i): (scm_integer_negate_z): (scm_integer_sub_ii): (scm_integer_sub_iz): (scm_integer_sub_zi): (scm_integer_sub_zz): New internal functions.
2022-01-13Clean up scm_sumAndy Wingo3-144/+126
* libguile/integers.h: * libguile/integers.c (scm_integer_to_double_z): (scm_integer_add_ii, scm_integer_add_zi, scm_integer_add_zz): New internal functions. * libguile/numbers.c (sum): New helper for scm_sum. Clean up to avoid repetition. The dispatch is less optimal but the code is shorter and more maintainable; in any case if speed is important, the compiler needs to be involved. (scm_sum): Adapt.
2022-01-13Simplify implementation of min, maxAndy Wingo1-283/+47
* libguile/numbers.c (scm_max, scm_min): Lean more on scm_is_less_than.