1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

574 commits

Author SHA1 Message Date
Andy Wingo
f6ec873a8b Move "min" and "max" macros out of _scm.h
* libguile/_scm.h: Remove definitions of min and max macros.
* libguile/array-map.c (MAX):
* libguile/foreign.c (MAX):
* libguile/numbers.c (MIN):
* libguile/quicksort.i.c (MIN):
* libguile/socket.c (MAX):
* libguile/strports.c (MAX): Inline definitions into callers.  We're
  going to remove _scm.h, which will pay off this duplication.
2018-06-17 13:41:03 +02:00
Andy Wingo
83584ef231 Fix libguile subcomponent headers not to include <libguile.h>
* libguile/bytevectors.h: Include uniform.h, for use in the macros.
* libguile/extensions.h: Include libpath.h, for the
  SCM_EFFECTIVE_VERSION, which is almost always used with these
  routines.
* libguile/frames.h:
* libguile/instructions.h:
* libguile/intrinsics.h:
* libguile/loader.h:
* libguile/programs.h:
* libguile/vm.h: Include <libguile/__scm.h> instead of <libguile.h>.
  Cuts a circular include, but also precipitates a lot of maintenance in
  the .c files.

* libguile/*.c: Update C files to add needed all needed includes that
  before were getting automatically pulled in by the indirect inclusion
  of libguile.h.
2018-06-14 22:20:47 +02:00
Andy Wingo
c248ea10be Remove all deprecated code
* module/ice-9/debug.scm:
* module/ice-9/mapping.scm:
* module/ice-9/syncase.scm: Delete these deprecated files.
* module/Makefile.am: Remove deleted files.
* libguile/deprecated.c:
* libguile/deprecated.h:
* libguile/backtrace.c:
* libguile/goops.c:
* libguile/numbers.c:
* libguile/socket.c:
* libguile/srfi-13.c:
* module/ice-9/deprecated.scm:
* module/ice-9/format.scm:
* module/oop/goops.scm:
* module/statprof.scm:
* module/texinfo/reflection.scm:
* module/web/client.scm:
* module/web/uri.scm: Remove deprecated code.
2017-05-22 13:36:42 +02:00
Mark H Weaver
1d257c27f0 Do not assume that sizeof (long) == sizeof (void *) == sizeof (SCM).
This assumption does not hold on systems that use the LLP64 data model.

Partially fixes <https://debbugs.gnu.org/22406>.
Reported by Peter TB Brett <peter@peter-b.co.uk>.

* libguile/numbers.h (scm_t_inum): Move here from numbers.c, and change
  to be equivalent to 'long' (formerly 'scm_t_signed_bits').
  (SCM_MOST_POSITIVE_FIXNUM, SCM_MOST_NEGATIVE_FIXNUM): Define based on
  SCM_I_FIXNUM_BIT instead of SCM_T_SIGNED_BITS_MAX.
  (SCM_I_INUM): Adjust definitions to return a 'scm_t_inum', and avoiding
  the assumption that SCM_UNPACK returns a 'long'.
* libguile/numbers.c (scm_t_inum): Move definition to numbers.h.
  Verify that 'scm_t_inum' fits within a SCM value.
  (scm_i_inum2big): Remove preprocessor code that forced a compile error
  unless sizeof (long) == sizeof (void *).
2017-03-01 19:08:42 +01:00
Mark H Weaver
a8d1c7d610 Avoid signed integer overflows in numeric conversions.
Reported by Miroslav Lichvar <mlichvar@redhat.com>
in <https://lists.gnu.org/archive/html/guile-devel/2016-02/msg00045.html>

* libguile/conv-integer.i.c: Avoid signed overflow.
* libguile/numbers.c (scm_is_signed_integer): Avoid signed overflow.
2017-03-01 19:05:30 +01:00
Andy Wingo
70d4c4b284 Fix (* x -1) for GOOPS types
* libguile/numbers.c (scm_product): Only reduce (* x -1) to (- x) when X
  is a bignum.  Fixes weirdness when X is not a number and instead
  multiplication should dispatch to GOOPS.  Thanks to Alejandro Sanchez
  for the report.
2017-02-28 10:12:57 +01:00
Andy Wingo
5333642b71 Use labs instead of abs where needed
* libguile/numbers.c (log_of_fraction): Use labs instead of abs on
  longs.  Thanks to Matt Wette for the tip.
2017-02-21 22:12:18 +01:00
Matt Wette
c4b0491e91 Fix make-polar signedness of zeros on macOS
* configure.ac: Check for __sincos.
* libguile/numbers.c (scm_c_make_polar): Fall back to __sincos if
  possible.  Fixes zero signedness of make-polar on macOS.
2017-02-21 22:09:01 +01:00
Andy Wingo
bfa6c401ce Speed up number->string
* libguile/numbers.c (scm_number_to_string): Use scm_from_latin1_string
  where appropriate.  Avoids mucking about with iconv.
2017-02-17 11:58:22 +01:00
Andy Wingo
dc2a560264 Deprecate dynamic roots
* libguile/root.h:
* libguile/root.c: Remove these files.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_internal_cwdr, scm_call_with_dynamic_root)
  (scm_dynamic_root, scm_apply_with_dynamic_root): Deprecate.

Remove all root.h usage, which was vestigial.

* module/ice-9/serialize.scm: Use (current-thread) instead
  of (dynamic-root).
2016-11-21 23:09:21 +01:00
Mark H Weaver
aa13da5189 Fix atan procedure when applied to complex numbers.
Fixes a regression introduced in commit
ad79736c68.

* libguile/numbers.c (scm_atan): Fix the complex case.
* test-suite/tests/numbers.test ("atan"): Add test.
2016-05-22 19:29:38 +02:00
Mark H Weaver
30db824b92 Don't return expressions from void functions in numbers.c
Although popular compilers allow it as long as the expression is of type
void, it violates C99 and some compilers choke on it.

* libguile/numbers.c (scm_euclidean_divide, scm_floor_divide)
  (scm_ceiling_divide, scm_truncate_divide, scm_centered_divide)
  (scm_round_divide): Don't use the return statement with an expression
  from functions with return type void.
2016-05-22 19:07:56 +02:00
Andy Wingo
15d5304723 scm_lfwrite, not scm_lfwrite_unlocked
* libguile/ports.h (scm_lfwrite_unlocked): Remove.
* libguile/ports.c (scm_lfwrite): Rename from scm_lfwrite_unlocked.
* libguile/numbers.c:
* libguile/print.c: Adapt to call scm_lfwrite.
2016-04-26 23:17:22 +02:00
Mark H Weaver
475772ea57 Merge branch 'stable-2.0'
Conflicts:
	GUILE-VERSION
	NEWS
	guile-readline/ice-9/readline.scm
	libguile/async.c
	libguile/backtrace.c
	libguile/deprecated.h
	libguile/gc-malloc.c
	libguile/gdbint.c
	libguile/init.c
	libguile/ioext.c
	libguile/mallocs.c
	libguile/print.c
	libguile/rw.c
	libguile/scmsigs.c
	libguile/script.c
	libguile/simpos.c
	libguile/snarf.h
	libguile/strports.c
	libguile/threads.c
	libguile/vm-i-scheme.c
	libguile/vm-i-system.c
	module/srfi/srfi-18.scm
	test-suite/Makefile.am
	test-suite/standalone/test-num2integral.c
2014-04-25 02:06:01 -04:00
Mark H Weaver
03cce0ce5f Avoid undefined behavior regarding signed integers and left shifts.
* libguile/numbers.c (scm_logbit_p): If the requested bit is the sign
  bit (or above), check the sign portably.  Otherwise, ensure that we're
  testing the bit in a two's complement representation.
  (left_shift_exact_integer): Avoid left-shifting negative integers.

* libguile/vm-i-scheme.c (ash): Avoid left-shifting negative integers.
2014-03-11 21:39:13 -04:00
Mark H Weaver
1df515a077 Merge branch 'stable-2.0'
Conflicts:
	module/system/vm/traps.scm
	test-suite/tests/peval.test
2014-01-09 02:52:34 -05:00
Mark H Weaver
900a897cd3 Implement 'exact-integer?' and 'scm_is_exact_integer'.
* libguile/numbers.c (scm_exact_integer_p, scm_is_exact_integer):
  New procedures.
  (scm_integer_p): Improve docstring.

* libguile/numbers.h (scm_exact_integer_p, scm_is_exact_integer):
  New prototypes.

* doc/ref/api-data.texi (Integers): Add docs.

* test-suite/tests/numbers.test ("exact-integer?"): Add tests.
2014-01-08 21:42:16 -05:00
Andy Wingo
091dd0cc58 Merge commit 'd360671c1c' 2013-11-28 14:46:24 +01:00
Mark H Weaver
d360671c1c Fix edge case in 'ash'.
* libguile/numbers.c (left_shift_exact_integer): Fix edge case where
  N is -1 and count is SCM_I_FIXNUM_BIT-1 to return the most negative
  fixnum.  Previously this result was returned as a bignum.

* test-suite/tests/numbers.test (ash): Add tests.
2013-10-03 19:08:24 -04:00
Mark H Weaver
1ea0803e9e Revert "Fix edge case in 'ash'."
This reverts commit 8df68898b9.
2013-10-03 19:08:23 -04:00
Andy Wingo
d7928d7c61 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/deprecated.h
	libguile/programs.c
	libguile/programs.h
2013-10-03 21:35:21 +02:00
Mark H Weaver
8df68898b9 Fix edge case in 'ash'.
* libguile/numbers.c (scm_ash): Fix (ash -1 SCM_I_FIXNUM_BIT-1) to
  return a fixnum instead of a bignum.

* test-suite/tests/numbers.test (ash): Add tests.
2013-10-03 14:25:51 -04:00
Andy Wingo
6871327742 Micro-optimize char_decimal_value.
* libguile/numbers.c (char_decimal_value): A wee micro-optimization.
2013-08-31 11:15:01 +02:00
Mark H Weaver
1160e2d94e Merge remote-tracking branch 'origin/stable-2.0' 2013-08-11 22:46:22 -04:00
Mark H Weaver
6f82b8f623 Fix inappropriate uses of scm_syserror in numbers.c.
* libguile/numbers.c (mem2ureal, left_shift_exact_integer,
  floor_right_shift_exact_integer, round_right_shift_exact_integer):
  Use 'assert' instead of 'scm_syserror' to indicate a case that should
  never happen.
2013-08-10 11:53:23 -04:00
Mark H Weaver
fa102e73c3 Fix numerator and denominator handling of signed zeroes and infinities.
* libguile/numbers.c (scm_numerator, scm_denominator): Handle signed
  zeroes and infinities in accordance with the corresponding R6RS flonum
  procedures.

* module/rnrs/arithmetic/flonums.scm (flnumerator, fldenominator):
  Remove special handling of infinities.

* test-suite/tests/numbers.test (numerator, denominator): Add tests.
  Convert existing tests to use 'pass-if-equal'.

* test-suite/tests/r6rs-arithmetic-flonums.test (flnumerator): Fix
  broken test of (flnumerator -0.0).
2013-08-09 06:09:56 -04:00
Mark H Weaver
056e3470c4 Eliminate use of deprecated 'SCM_WTA_DISPATCH_2' in numbers.c.
* libguile/numbers.c (scm_gcd): Use 'scm_wta_dispatch_2' not
  'SCM_WTA_DISPATCH_2'.
2013-08-08 02:19:46 -04:00
Mark H Weaver
d8d7c7bf57 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/numbers.c
	libguile/vm-i-scheme.c
2013-08-06 17:37:34 -04:00
Mark H Weaver
19374ad2de Use Gnulib's 'isfinite' in numbers.c.
* libguile/numbers.c (DOUBLE_IS_FINITE, DOUBLE_IS_POSITIVE_INFINITY,
  DOUBLE_IS_NEGATIVE_INFINITY): Remove.
  (scm_odd_p, scm_even_p, scm_finite_p, icmplx2str, scm_rational_p,
  scm_inexact_to_exact): Use 'isfinite' instead of 'DOUBLE_IS_FINITE'.
2013-08-06 16:26:46 -04:00
Mark H Weaver
e1592f8a40 Use Gnulib's 'copysign' in numbers.c.
* libguile/numbers.c (double_is_non_negative_zero): Remove.
  (idbl2str, scm_max, scm_min, scm_angle, log_of_shifted_double,
  scm_log10): Use 'copysign' to check signs of zeroes,
  instead of 'double_is_non_negative_zero'.
2013-08-06 16:21:26 -04:00
Mark H Weaver
00472a22bb Add 'scm_i_from_double' and use it.
* libguile/numbers.c (scm_i_from_double): New static function.
  (scm_from_double): Just call 'scm_i_from_double'.
  (scm_inf, scm_nan, scm_abs, scm_i_inexact_floor_quotient,
  scm_i_inexact_floor_remainder, scm_i_inexact_floor_divide,
  scm_i_inexact_ceiling_quotient, scm_i_inexact_ceiling_remainder,
  scm_i_inexact_ceiling_divide, scm_i_inexact_truncate_quotient,
  scm_i_inexact_truncate_remainder, scm_i_inexact_truncate_divide,
  scm_i_inexact_centered_quotient, scm_i_inexact_centered_remainder,
  scm_i_inexact_centered_divide, scm_i_inexact_round_quotient,
  scm_i_inexact_round_remainder, scm_i_inexact_round_divide,
  scm_max, scm_min, scm_sum, scm_difference, scm_product,
  scm_divide, scm_truncate_number, scm_round_number, scm_floor,
  scm_ceiling, scm_expt, scm_sin, scm_cos, scm_tan, scm_sinh,
  scm_cosh, scm_tanh, scm_asin, scm_acos, scm_atan, scm_sys_asinh,
  scm_sys_acosh, scm_sys_atanh, scm_real_part, scm_imag_part,
  scm_magnitude, scm_angle, scm_exact_to_inexact, log_of_shifted_double,
  log_of_fraction, scm_log10, scm_exp, scm_sqrt, scm_init_numbers):
  Use 'scm_i_from_double' instead of 'scm_from_double'.
2013-08-02 12:04:20 -04:00
Mark H Weaver
d9e7774fda Fix minor formatting error in 'rationalize'.
* libguile/numbers.c (scm_rationalize): Fix formatting.
2013-07-21 07:20:03 -04:00
Mark H Weaver
620c13e8fc Rewrite 'rationalize' to fix bugs and improve efficiency.
Fixes <http://bugs.gnu.org/14905>.
Reported by Göran Weinholt <goran@weinholt.se>.

* libguile/numbers.c (scm_rationalize): Rewrite.  Previously an
  incorrect algorithm was used which failed in many cases.

* test-suite/tests/numbers.test (rationalize): Add tests.
2013-07-21 06:44:54 -04:00
Mark H Weaver
902a4e779d Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/numbers.c
2013-07-16 06:49:20 -04:00
Mark H Weaver
3bbca1f723 gcd and lcm support inexact integer arguments.
Fixes <http://bugs.gnu.org/14870>.
Reported by Göran Weinholt <goran@weinholt.se>.

* libguile/numbers.c (scm_gcd, scm_lcm): Support inexact integers.

* test-suite/tests/numbers.test (gcd, lcm): Add tests.
2013-07-16 06:41:07 -04:00
Mark H Weaver
b4c55c9cce min and max: NaNs beat infinities, per R6RS errata.
Fixes <http://bugs.gnu.org/14865>.
Reported by Göran Weinholt <goran@weinholt.se>.

* libguile/numbers.c (scm_min, scm_max): NaNs beat infinities, as per
  the R6RS errata.

* test-suite/tests/numbers.test (min, max): Update tests.
2013-07-16 05:18:15 -04:00
Mark H Weaver
28d5d2537c Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/keywords.c
	libguile/vm.c
2013-07-16 01:33:27 -04:00
Mark H Weaver
95ed221785 Avoid lossy conversion from inum to double in numerical comparisons.
* libguile/numbers.c (scm_less_p): Avoid converting inums to doubles.

* test-suite/tests/numbers.test (<): Add tests.
2013-07-16 00:26:11 -04:00
Mark H Weaver
0132928891 Fix bugs in numerical equality predicate.
* libguile/numbers.c (scm_num_eq_p): Fix bug comparing fractions to
  infinities (reported by Göran Weinholt <goran@weinholt.se>).  Fix
  erroneous comment describing the logic behind inum/flonum comparison.
  Use similar logic for inum/complex comparison to avoid rounding
  errors.  Make minor indentation fixes and simplifications.

* test-suite/tests/numbers.test (=): Add tests.
2013-07-16 00:18:40 -04:00
Mark H Weaver
4cc2e41cf7 Fix rounding in scm_i_divide2double for negative arguments.
* libguile/numbers.c (INUM_LOSSLESSLY_CONVERTIBLE_TO_DOUBLE):
  New macro.
  (scm_i_divide2double): Use INUM_LOSSLESSLY_CONVERTIBLE_TO_DOUBLE to
  determine if our fast path is safe.  Previously, negative arguments
  were not checked properly.

* test-suite/tests/numbers.test (exact->inexact): Add tests.
2013-07-16 00:00:23 -04:00
Mark H Weaver
c33ecf96a4 Merge remote-tracking branch 'origin/stable-2.0' 2013-03-28 22:24:00 -04:00
Ludovic Courtès
07b390d582 Allow compilation with GMP < 5.0.0.
* libguile/numbers.c (VARARG_MPZ_ITERATOR)[!HAVE_DECL_MPZ_INITS]: New
  macro.
  (mpz_inits, mpz_clears)[!HAVE_DECL_MPZ_INITS]: New functions.
* configure.ac: Check for the declaration of `mpz_inits'.
2013-03-28 22:19:12 +01:00
Mark H Weaver
26d148066f Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	configure.ac
	libguile/deprecated.c
	libguile/deprecated.h
	libguile/filesys.h
	libguile/fluids.c
	libguile/fports.c
	libguile/gc.c
	libguile/guile.c
	libguile/numbers.c
	libguile/objcodes.c
	libguile/r6rs-ports.c
	libguile/smob.c
	libguile/socket.c
	libguile/threads.h
	module/language/scheme/decompile-tree-il.scm
	module/language/tree-il/peval.scm
	test-suite/tests/syncase.test
2013-03-28 05:09:53 -04:00
Mark H Weaver
ddb7174236 Improve sqrt handling of large integers and large and small rationals.
* libguile/numbers.c (exact_integer_is_perfect_square,
  exact_integer_floor_square_root): New static functions.

  (scm_sqrt): Use SCM_LIKELY.  Add 'scm_t_inum' variable in inum case to
  reduce the number of uses of SCM_I_INUM.  Rename 'mpz_t' variable.
  Remove unneeded sign check.  Handle bignums too large to fit in a
  double.  Handle fractions too large or too small to fit in a
  normalized double.

* test-suite/tests/numbers.test ("sqrt"): Add tests.
2013-03-20 06:27:39 -04:00
Mark H Weaver
687a87bf01 Optimize inum case of exact-integer-sqrt.
* libguile/numbers.c (scm_exact_integer_sqrt): Use GMP for inum
  case.  It is faster than what we had before.
2013-03-20 02:27:10 -04:00
Mark H Weaver
4400266478 Sqrt returns exact results when possible.
* libguile/numbers.c (scm_sqrt): Handle exact integers and rationals in
  such a way that exact results are returned whenever possible.

* test-suite/tests/numbers.test ("sqrt"): Add tests.
2013-03-20 00:13:43 -04:00
Mark H Weaver
c8248c8ed5 Optimize scm_i_divide2double for integers less than 2^DBL_MANT_DIG.
* libguile/numbers.c (scm_i_divide2double): Optimize for common case
  when both operands are less than 2^DBL_MANT_DIG (normally 2^53).
2013-03-19 22:41:18 -04:00
Mark H Weaver
8150dfa1f2 Use scientific notation only if there are enough trailing zeroes.
* libguile/numbers.c (idbl2str): Print large numbers in scientific
  notation only if the exponent is >= 7 and the least significant
  non-zero digit has value >= radix^4.

* test-suite/tests/numbers.test ("number->string"): Add tests.
2013-03-19 03:38:15 -04:00
Mark H Weaver
1ea37620c2 Reimplement idbl2str number printer.
Fixes <http://bugs.gnu.org/13757>.

* libguile/numbers.c (idbl2str): Reimplement.
  (mem2decimal_from_point): Accept negative exponents larger than
  SCM_MAXEXP that produce subnormals.
  (SCM_MAX_DBL_PREC): Removed preprocessor macro.
  (scm_dblprec, fx_per_radix): Removed static variables.
  (init_dblprec, init_fx_radix): Removed static functions.
  (scm_init_numbers): Remove initialization code for 'scm_dblprec'
  and 'fx_per_radix'.

* test-suite/tests/numbers.test ("number->string"): Restore tests that
  previously failed.  Remove comments about problems in the number
  printer that are now fixed.
2013-03-17 18:52:31 -04:00
Mark H Weaver
9823778490 Improve inexact division of exact integers.
* libguile/numbers.c (scm_i_divide2double): New function.
  (scm_i_divide2double_lo2b): New variable.
  (scm_i_fraction2double, log_of_fraction): Use 'scm_i_divide2double'.
  (do_divide): Removed.  Its code is now in 'scm_divide'.
  (scm_divide2real): Removed.  Superceded by 'scm_i_divide2double'.
  (scm_divide): Inherit code from 'do_divide', but without support for
  forcing a 'double' result (that functionality is now implemented by
  'scm_i_divide2double').  Add FIXME comments in cases where divisions
  might not be as precise as they should be.
  (scm_init_numbers): Initialize 'scm_i_divide2double_lo2b'.

* test-suite/tests/numbers.test (dbl-epsilon-exact, dbl-max-exp): New
  variables.
  ("exact->inexact"): Add tests.
  ("inexact->exact"): Add test for largest finite inexact.
2013-03-17 16:37:55 -04:00