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

471 commits

Author SHA1 Message Date
Kevin Ryde
238ebcef24 (s_bignum): Remove, not used since gmp bignums.
Reported by Richard Todd.
2004-01-06 21:55:29 +00:00
Kevin Ryde
a5f0b59988 (scm_less_p): Don't convert frac to float for compares,
can give wrong results due to rounding.
2004-01-03 21:38:38 +00:00
Kevin Ryde
084b1d8eec (scm_less_p): Remove spurious xisnan from frac+big case. 2003-12-02 21:36:39 +00:00
Kevin Ryde
2fa2d87937 (scm_real_part): Return fraction unchanged rather than converting to flonum. 2003-12-02 21:27:13 +00:00
Kevin Ryde
dd5130cadf (scm_make_ratio): Check for numerator equal to
SCM_MOST_NEGATIVE_FIXNUM and bignum denominator the negative of that,
giving integer -1.
2003-12-02 21:21:14 +00:00
Marius Vollmer
535f2a516a (scm_logand): It's "#b...", not "#\b...". 2003-11-30 00:59:40 +00:00
Kevin Ryde
7f84824269 (scm_bit_extract): Use mpz functions, rearrange inum case
to share some shifting.
2003-11-21 00:33:44 +00:00
Kevin Ryde
ae38324d9c (scm_abs): Allocate a new real only for negatives, as done for bignums. 2003-11-21 00:07:13 +00:00
Kevin Ryde
753ac1e7e1 (scm_integer_expt): Don't mpz_init after scm_i_clonebig or
scm_i_mkbig, since they do so already.  Don't mpz_clear a bignum SCM,
since gc does this.
2003-11-21 00:03:54 +00:00
Marius Vollmer
c60e130c97 * numbers.c (scm_make_ratio): Rewritten to have a simpler
structure.  Previously, not all cases with a negative denominator
were covered.
2003-11-19 05:12:08 +00:00
Marius Vollmer
0b0c8e3b4c * numbers.c (scm_make_ratio): Don't declare divisible_p after
statements.
2003-11-19 04:30:40 +00:00
Marius Vollmer
02164269a7 * numbers.c (scm_i_fraction_equalp): Do not treat the return value
of scm_equal_p as a C boolean, use SCM_FALSEP.  Previously, all
fractions were equal to each other regardless of value.  Ooops.

* numbers.c (scm_rationalize): Return an inexact result when given
inexact arguments.
2003-11-19 03:50:26 +00:00
Marius Vollmer
eb927cb95c * numbers.c (scm_exact_p, scm_inexact_p): Throw error for non-numbers. 2003-11-19 02:38:37 +00:00
Marius Vollmer
d8592269ab (mem2decimal_from_point): use scm_divide instead of scm_divide2real
when forming the fractional part.  This allows "#e1.2" to yield 6/5.
2003-11-19 02:19:03 +00:00
Marius Vollmer
f92e85f735 * print.c (scm_iprin1): Handle fractions.
* objects.h (scm_class_fraction): New.
* objects.c (scm_class_fraction): New.
(scm_class_of): Handle fractions.

* hash.c (scm_hasher): Handle fractions.

* numbers.c: New code for handling fraction all over the place.
(scm_odd_p, scm_even_p): Handle inexact integers.
(scm_rational_p): New function, same as scm_real_p.
(scm_round_number, scm_truncate_number, scm_ceiling, scm_floor):
New exact functions that replace the inexact 'dsubr'
implementations.
(scm_numerator, scm_denominator): New.

* numbers.h (SCM_NUMP): Recognize fractions.
(SCM_FRACTIONP, SCM_SLOPPY_FRACTIONP, SCM_FRACTION_NUMERATOR,
SCM_FRACTION_DENOMINATOR, SCM_FRACTION_SET_NUMERATOR,
SCM_FRACTION_SET_DENOMINATOR, SCM_FRACTION_REDUCED_BIT,
SCM_FRACTION_REDUCED_SET, SCM_FRACTION_REDUCED_CLEAR,
SCM_FRACTION_REDUCED): New.
(scm_floor, scm_ceiling, scm_truncate_number, scm_round_number):
New prototypes.
(scm_make_ratio, scm_rationalize, scm_numerator, scm_denominator,
scm_rational_p): New prototypes.
(scm_i_dbl2num, scm_i_fraction2double, scm_i_fraction_equalp,
scm_i_print_fraction): New prototypes.

* goops.c (create_standard_classes): Create "<fraction>" class.

* gc-mark.c (scm_gc_mark_dependencies): Handle fractions.

* gc-card.c (scm_i_sweep_card): Include scm_tc16_fraction as a
case in the switch, but do nothing for now.

* eval.c (SCM_CEVAL, SCM_APPLY, call_dsubr_1): Convert fractions
to doubles when calling 'dsubr' functions.

* eq.c (scm_eqv_p, scm_equal_p): Handle fractions.
2003-11-18 19:59:53 +00:00
Kevin Ryde
089c9a5909 (scm_i_big2dbl): Rewrite, carefully rounding to "closest"
in accordance with R5RS, which just mpz_get_d doesn't really give.
2003-10-19 00:32:25 +00:00
Kevin Ryde
32f19569bc (scm_ash): Revise docstring as per recent update to manual. 2003-10-19 00:27:00 +00:00
Kevin Ryde
2be24db4d7 (scm_inexact_to_exact): Don't depend on what double->long
cast gives for values bigger than a long, or for nan or inf.
2003-10-09 00:38:51 +00:00
Dirk Herrmann
534c55a97d This set of patches introduces a new tc7 code scm_tc7_number for
numbers.  Bignums, reals and complex numbers are turned from smobs
	into subtypes of scm_tc7_number.

	* tags.h (scm_tc7_number): New.

	* eq.c (scm_equal_p), eval.c (SCM_CEVAL), evalext.c
	(scm_self_evaluating_p), gc-card.c (scm_i_sweep_card), gc-mark.c
	(scm_gc_mark_dependencies), goops.c (create_smob_classes), hash.c
	(scm_hasher), numbers.c, numbers.h (SCM_NUMP), objects.c
	(scm_class_of), print.c (scm_iprin1), smob.c
	(scm_smob_prehistory): Don't handle bignums, reals and complex
	numbers as subtypes of scm_tc7_smob any more.

	* numbers.h, tags.h (scm_tc16_big, scm_tc16_real,
	scm_tc16_complex): Moved definitions from tags.h to numbers.h.
2003-09-18 20:55:40 +00:00
Dirk Herrmann
29c4382afd * numbers.c (scm_make_complex), gc-card.c (scm_i_sweep_card): Use
sizeof (scm_t_complex) to determine the memory size of the
	malloc'd area for complex numbers.
2003-09-18 20:18:17 +00:00
Dirk Herrmann
47ae1f0eca * libguile/numbers.c (scm_bigequal): Fixed.
* test-suite/tests/numbers.test (equal?): Added tests.

	* test-suite/tests/numbers.test (=): Fixed and added some bignum
        related tests.
2003-09-17 21:03:26 +00:00
Kevin Ryde
4d814788fc (scm_lognot): Correction to docstring, ones-complement not 2s-complement. 2003-09-02 23:00:28 +00:00
Kevin Ryde
f9811f9f2e (scm_lognot): Rewrite using ~ and mpz_com, for directness
and to have non-integer types rejected as per other logical funcs.
2003-08-30 00:04:42 +00:00
Kevin Ryde
708f22c6af (scm_difference): Correction to bignum - negative inum. 2003-08-22 01:17:48 +00:00
Marius Vollmer
570b6821e3 * __scm.h (SCM_C_INLINE_KEYWORD): New.
* numbers.c: Use it in place of SCM_C_INLINE so that the code
compiles when SCM_C_INLINE is undefined.
2003-07-27 13:34:32 +00:00
Kevin Ryde
c8ae173e8a (scm_angle): Use scm_flo0 for non-negative inum, bignum and real. 2003-07-24 01:03:40 +00:00
Kevin Ryde
7650633547 (scm_product): In complex * bignum, correction to
REAL/IMAG fetch, x is the complex, not y.
2003-07-17 23:38:34 +00:00
Mikael Djurfeldt
0aacf84ee6 (scm_odd_p, scm_even_p): Bugfix: Treat result of
scm_inf_p test as Scheme values.
(scm_sum): Bugfix: Normalize bignum created from a negative bignum
and a positive inum.
Use GNU indentation style.
2003-07-13 16:13:57 +00:00
Kevin Ryde
6efadd7cb6 (scm_make_polar): Use sincos, when available.
(scm_magnitude): Use hypot.
2003-07-08 00:27:03 +00:00
Kevin Ryde
fa60559018 (_GNU_SOURCE): #define, to get C99 things.
(scm_asinh, scm_acosh, scm_atanh, scm_truncate, $asinh, $acosh,
$atanh, truncate): Use C library asinh, acosh, atanh and trunc, when
available.
(scm_inexact_to_exact): Expand isfinite to its definition !isinf.
(isfinite): Remove, conflicts with C99 isfinite().
2003-06-21 00:12:51 +00:00
Kevin Ryde
e06beeadda (scm_max, scm_min): For inum, bignum and real, if other
operand is NaN, then return NaN.  Also avoid passing NaN to mpz_cmp_d.
2003-06-04 16:09:38 +00:00
Dirk Herrmann
14b18ed6f5 This set of patches separates the representation of the cxr family
of functions (car, cdr etc.) from the dsubr family of functions
	(i. e. functions that take a double precision floating point
	argument).  Further, the algorithm for handling the cxr function
	is improved.

	* eval.c (SCM_CEVAL, SCM_APPLY, scm_trampoline_1), numbers.c
	(scm_asinh, scm_acosh, scm_atanh, scm_truncate, scm_round, floor,
	ceil, sqrt, fabs, exp, log, sin, cos, tan, asin, acos, atan, sinh,
	cosh, tanh), objects.c (scm_class_of), procprop.c
	(scm_i_procedure_arity), ramap.c (scm_array_map_x), tags.h
	(scm_tc7_dsubr, scm_tcs_subrs): Introduce scm_tc7_dsubr as new
	typecode for the dsubr family of functions.

	* ramap.c (ramap_cxr, ramap_dsubr): Renamed ramap_cxr to
	ramap_dsubr.

	* eval.c (SCM_CEVAL, SCM_APPLY, call_cxr_1), pairs.c
	(scm_init_pairs): Make use of the (now usable) second cell element
	of a scm_tc7_cxr function to implement the cxr family of functions
	more efficiently.
2003-06-01 13:58:42 +00:00
Kevin Ryde
713a425913 (z_negative_one): New variable.
(scm_init_numbers): Initialize it.
(scm_logcount): Use it and mpz_hamdist to count zeros for negatives.
2003-05-30 00:23:11 +00:00
Kevin Ryde
b127c712ea (xmpz_cmp_d): New macro, handling infs if gmp doesn't.
(scm_num_eq_p, scm_less_p, scm_max, scm_min): Use it.
2003-05-12 23:16:43 +00:00
Kevin Ryde
8c5b0afcbf (scm_gcd): In bignum/inum, don't pass yy==0 to mpz_gcd_ui
since we're only using the ulong return value, and x might not fit.
2003-05-10 00:20:05 +00:00
Kevin Ryde
2c57607ca8 (scm_integer_length): On negative bignums, adjust
mpz_sizeinbase to account for it looking at absolute value where we
want ones-complement.
2003-05-10 00:05:51 +00:00
Kevin Ryde
2b031f4f65 (scm_num_eq_p, scm_less_p): Don't pass NaN to mpz_cmp_d. 2003-05-09 23:14:35 +00:00
Kevin Ryde
c78b590e56 (scm_logcount): Use mpz_com, not mpz_neg. 2003-05-05 23:01:30 +00:00
Kevin Ryde
9c4443d38c (scm_difference): In inum - bignum, handle negative inum. 2003-05-05 22:55:46 +00:00
Marius Vollmer
9dd023e147 Doc fix for the usage of num2intergral. 2003-05-03 23:19:51 +00:00
Dirk Herrmann
aec16f9972 * numbers.c (scm_logtest): Fixed argument bug in the call to
mpz_and, which showed up when compiling with SCM_DEBUG defined.
2003-04-20 08:55:50 +00:00
Rob Browning
1c35cb199f * numbers.c (scm_integer_expt): fix case where we were declaring
vars in the middle of a statement block.  Thanks to Thamer
Al-Harbash.
2003-04-17 22:15:37 +00:00
Rob Browning
b4fb7de868 * numbers.c (PTRDIFF_MIN): use SCM_CHAR_BIT. 2003-04-16 19:44:02 +00:00
Rob Browning
876173478e *** empty log message *** 2003-04-07 17:36:17 +00:00
Marius Vollmer
73be1d9e8e Changed license terms to the plain LGPL thru-out. 2003-04-05 19:15:35 +00:00
Rob Browning
ca46fb9018 * numbers.c: rewrite *many* functions to handle GMP bignums. 2003-04-04 21:49:44 +00:00
Rob Browning
ee33d62a8d * numbers.c: #include <config.h> if HAVE_CONFIG_H. Replace usage
of HAVE_LONG_LONGS with "SCM_SIZEOF_LONG_LONG != 0".  Replace
usage of ptrdiff_t with scm_t_ptrdiff.  Replace usage of
SIZEOF_PTRDIFF_T with SCM_SIZEOF_SCM_T_PTRDIFF.
2003-03-25 23:57:51 +00:00
Mikael Djurfeldt
a48d60b1c0 * srfi-1.c (scm_init_srfi_1): Extend root module map and for-each
with the versions in this module using
scm_c_extend_primitive_generic.

* goops.scm (equal?): Define default method.

* goops.c (scm_primitive_generic_generic): Enable primitive
generic if not enabled.
(scm_sys_goops_loaded): Setup unextended primitive generics.

* goops.c, goops.h (scm_c_extend_primitive_generic): New function.

* snarf.h (SCM_PRIMITIVE_GENERIC, SCM_PRIMITIVE_GENERIC_1): New
snarf macros.

* numbers.c (scm_abs): Use SCM_PRIMITIVE_GENERIC.  (This is only a
testing example.  All uses of SCM_GPROC should be converted.)

* procprop.c (scm_stand_in_scm_proc): Use scm_assq instead of
scm_assoc.

* eq.c (scm_equal_p): Turned into a primitive generic.
2003-03-06 12:51:57 +00:00
Marius Vollmer
7b3381f44d (scm_integer_expt): Make 0^z == 0 for z != 0. Also for reals. 2002-11-03 21:57:48 +00:00
Marius Vollmer
d57ed70201 (scm_integer_expt): Make 0^z == 0 for z != 0. 2002-11-03 17:13:50 +00:00