summaryrefslogtreecommitdiffstats
path: root/arith.c
Commit message (Collapse)AuthorAgeFilesLines
* * arith.c (highest_bit): Changing to external linkage.Kaz Kylheku2011-12-231-1/+1
| | | | | | | | * arith.h (highest_bit): Declared. * rand.c (random): Rewrote using different algorithm which ensures even distribution, and avoids doing a bignum mod operation.
* Bug #35136 and cleanup.Kaz Kylheku2011-12-221-32/+28
| | | | | | | | | | | * arith.c (plus, minus, mul, gt, ge, lt, le, exptmod, gcd): Remove trailing abort; we already marked uw_throwf as noreturn. This hack should not be needed in functions where the last statement is a throw. (trunc, expt): Repeated error case handled in one place. Temp variable used to avoid two calls to mp_clear. Call to abort removed. (mod): Repeated error handed in one place. Plugged memory leak by moving throw past mp_clear calls. Call to abort removed. (isqrt): Repeated error case handed in one place.
* * arith.c (normalize): Linkage changed to extern.Kaz Kylheku2011-12-211-1/+1
| | | | | | | | * arith.h (normalize): Declared. * rand.c (random): Bugfix: normalize the bignum before returning it. * txr.1: Doc stubs for PRNG functionality.
* * arith.c (abso): broken for fixnums.Kaz Kylheku2011-12-141-1/+1
|
* * arith.c (minus): Allow difference between characters.Kaz Kylheku2011-12-141-0/+1
|
* * arith.c (plus, minus, gt, lt, ge, le): Handle character operands.Kaz Kylheku2011-12-141-0/+56
| | | | | | | | | | * eval.c (eval_init): New functions interned. * lib.c (num_chr, chr_num): New functions. * lib.h (num_chr, chr_num): Declared. * txr.1: Documentation stubs.
* * arith.c (exptmod, gcd): New functions.Kaz Kylheku2011-12-131-0/+53
| | | | | | | | * eval.c (eval_init): New functions registered as intrisics. * lib.h (exptmod, gcd): Declared. * txr.1: Documentation stubs added.
* * arith.c (evenp, oddp): New functions.Kaz Kylheku2011-12-131-0/+30
| | | | | | | | * eval.c (eval_init): New functions registered as intrinsics. * lib.h (evenp, oddp): Declared. * txr.1: Documentation stub updated.
* * arith.c (highest_bit): Linkage changed to static.Kaz Kylheku2011-12-131-1/+43
| | | | | | | | | | | | | | | | | (abso, isqrt): New functions. (isqrt_fixnum): New static function. * eval.c (eval_init): Registered abs, sqrt and numberp instrinsics. * lib.c (numberp): New function. * lib.h (numberp, abso, isqrt): Declared. * mpi-patches/series: New patch added. * mpi-patches/faster-square-root: New patch added. * txr.1: Documentation stubs for new functions.
* * arith.c (expt): Fix broken bignum x fixnum combination.Kaz Kylheku2011-12-131-1/+1
|
* * arith.c (expt): New function.Kaz Kylheku2011-12-121-0/+89
| | | | | | | | | | | | * eval.c (eval_init): Registering new intrinsic functions, reduce-left, reduce-right and expt. * lib.c (minusv): Return one instead of num(1). (exptv, reduce_right): New functions. * lib.h (expt, exptv, reduce_right): Declared. * txr.1: Blank sections for new functions.
* * arith.c (zerop, gt, lt, ge, le): Functions from lib.c reimplementedKaz Kylheku2011-12-111-0/+112
| | | | | | | | | | | | | | | with bignum support. * eval.c (eval_init): Added bignump and zerop as intrinsic function. Renamed numberp to fixnump. * lib.c (zerop, gt, lt, ge, le): Functions removed. (numeq): Unused function removed. * lib.h (numeq): Declaration removed. * txr.1: Sections for zerop and bignump created. Changed reference to numberp to fixnump.
* * arith.c (plus, mul): Plugged mpi_int memory leaks.Kaz Kylheku2011-12-111-11/+85
| | | | | (trunc): Plugged memory leaks. Straightened out semantics with negative modulus. (Residue comes out negative).
* * arith.c (trunc): Error messages prefixed with trunc:.Kaz Kylheku2011-12-111-4/+61
| | | | | | (mod): New function, reimplementation of removed mod from lib.c. * lib.c (mod): Function removed.
* Bignum division implemented. More portability bugs found in MPI:Kaz Kylheku2011-12-111-0/+61
| | | | | | | | | | | code like 1 << n, where n exceeds the width of the type int. * arith.c (trunc): New function, reimplementation of removed trunc from lib.c. * lib.c (trunc): Removed. * mpi-patches/fix-bad-shifts: New file.
* * arith.c (ABS): New macro.Kaz Kylheku2011-12-111-10/+38
| | | | | | | (plus, minus): Bugfix: must not pass signed values to mp_add_d and mp_sub_d functions. (mul): Must not pass signed value to mp_mul_d. Also, fixed type check on wrong argument in the (TAG_PTR, TAG_NUM) case.
* Whitespace.Kaz Kylheku2011-12-111-24/+24
|
* * arith.c: Regenerated.Kaz Kylheku2011-12-111-9/+5
| | | | | * arith.txr (normalize): Bugfix: was not turning +/- NUM_MAX bignums into fixnums.
* * arith.c: Regenerated.Kaz Kylheku2011-12-111-0/+1
| | | | | * arith.txr (highest_bit): Missing #else added, fixing SIZEOF_PTR == 4 case.
* * arith.c: Regenerated.Kaz Kylheku2011-12-111-1/+55
| | | | | * arith.txr (highest_bit): Oops, half the logic for the 64 bit case was missing due to to a cut and paste mistake.
* * arith.c: Regenerated.Kaz Kylheku2011-12-111-13/+119
| | | | | * arith.txr (highest_bit): New function. (mul): Use highest_bit instead of shift based algorithm.
* Bignum support in mult function.Kaz Kylheku2011-12-101-12/+111
| | | | | | | | | | | | | | | | | | | | | | * arith.c: Regenerated. * arith.txr (CNUM_BIT): New constant. (bignum, bignum_dbl_ipt): New static functions. (@{add-fname}): Use bignum function. (mul): New functions, rewrite of mul from lib.c. * lib.c (mul): Function removed. * mpi-patches/add-mp-set-intptr (mp_set_intptr): Revised patch. Local variable v should be int_ptr_t not unsigned long. Also, the mp_set interface doesn't set the sign; it's an unsigned interface. We must do that ourselves. * mpi-patches/fix-mult-bug: The main multiplication function is also broken in the same way, requiring the cast. * mpi-patches/mpi-set-double-intptr: Fixed use of wrong type for local variable v.
* * arith.c: File is now generated using TXR.Kaz Kylheku2011-12-101-1/+82
| | | | | | | | | | | (NOOP): New macro. (plus): Use NOOP macro. (minus, neg): Function moved here from lib.c and rewritten for bignum support. * lib.c (minus, neg): Functions removed. * arith.txr: New file.
* Bignum support, here we go!Kaz Kylheku2011-12-091-0/+139
Bignums, based on Michael Fromberger's MPI library, are integrated into the input syntax, stream output, equality testing, the garbage collector, and hashing. The plus operation handles transitions between fixnums and bignums. Other operations are still fixnum only. * Makefile (CFLAGS): Add mpi directory to include file search. (OBJS): Include new arith.o module and all of MPI_OBJS. (MPI_OBJS, MPI_OBJS_BASE): New variables. * configure (mpi_version, have_quilt, have_patch): New variables. Script detects whether patch and quilt are available. Unpacks mpi library, applies patches. Detects 128 bit integer type. Records more information in config.h about the sizes of types. * dep.mk: Updated. * depend.txr: Make work with paths that have directory components. * eval.c (eval_init): Rename of nump to fixnump. * gc.c (finalize, mark_obj): Handle BGNUM case. * hash.c: (hash_c_str): Changed to return unsigned long instead of long. (equal_hash): Handle BGNUM case. (eql_hash): Handle bignums with equal-hash, but other objects as eq. * lib.c (num_s): Variable renamed to fixnum_s. (bignum_s): New symbol variable. (code2type): Follow rename of num_s. Handle BGNUM case. (typeof): Follow rename of num_s. (eql): Handle bignums using equal, and other types using eq. (equal): Handle BGNUM case. (chk_calloc): New function. (c_num): Wording change in error message: is not a fixnum. (nump): Renamed to fixnump. (bignump): New function. (plus): Function removed, reimplemented in arith.c. (int_str): Handle integers which are too large for wcstol using bignum conversion. Base 0 is no longer passed to wcstol but converted to 10 because the special semantics for 0 would be inconsistent for bignums. (obj_init): Follow rename of num_s. Initialize bignum_s.