| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
| |
* mpi.c (s_mp_ispow2): Delay call to s_highest_bit until that
value is actually needed. Perhaps the compiler does the code
motion, but let's write the code that way.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The MP_DEBUG macro controls the visibility of definitions that
are not used anywhere.
* mpi/mpi-config.h (MP_DEBUG): Removed.
* mpi/mpi.c (DIAG): Macro and surrounding section controlled
by #if MP_DEBUG removed.
* mpi/mpi.h (MP_IOFUNC): Definition controlled by MP_DEBUG
removed.
|
|
|
|
|
|
| |
* mpi.c (mp_bit): If the argument is negative, and we have
produced a temporary mp_int, we must clear it before
returning.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* configure: In several config tests, test HAVE_SUPERLONG_T,
HAVE_LONGLONG_T and HAVE_SYS_WAIT with #if.
* lib.c: Test HAVE_GETENVIRONMENTSTRINGS with #if.
* lib.h: Test HAVE_DOUBLE_INTPTR_T with #if.
* mpi/mpi.c: Likewise.
* mpi/mpi.h: Likewise.
* socket.c: Test HAVE_GETADDRINFO with #if in three places.
* stream.c: Test HAVE_SYS_WAIT and HAVE_SOCKETS with #if.
|
|
|
|
|
|
|
|
|
| |
* mpi.c (mp_set_int, mp_set_intptr, mp_set_double_intptr):
When the signed input is negative, do not simply calculate its
inverse with unary minus, because it could be the most
negative value that has no additive inverse. Instead, convert
to unsigned first, then apply the unary minus to the unsigned
type, which calculates the two's complement.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This bug causes a problem particularly in FFI. THe conversion
of an integer to the FFI int type begins by conversion via
c_num to the cnum type, which is at least as wide as int.
Alas, the INT_MIN value (e.g. #x-80000000 on 32 bits) will
not convert!
Fixing this has a ripple effect. We alter the INT_PTR_MIN
constant to include this value. This causes the derived
NUM_MIN to also include the extra negative value, extending
the fixnum range by one value. Everything seems to be okay.
* configure: Decrease value of INT_PTR_MIN and
DOUBLE_INTPTR_MIN constants by one to include the most
negative two's complement value.
* ffi.c (make_ffi_type_enum): We must not subtract 1 from
INT_PTR_MIN here any more.
* mpi.c (mp_in_range): If the bignum is negative, then extend
the range check by one value, so that we don't reject the
most negative two's complement value.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* mpi/logtab.h: Regenerated.
(s_logv_2): Now table of scaled integers.
(MP_LOG_SCALE): New constant.
* mpi/make-logtab.txr (scale, type): New variables.
Generate integer table with log2 values scaled by the scale
factor, rounded up.
* mpi/config.h (MP_LOGTAB): Removed. We always use the table.
* mpi/mpi.c: Unconditionally include logtab.h.
(LOG_V_2): Macro removed.
(s_mp_outlen): Rewritten using scaled integer math.
Overflow is avoided by splitting the input into a part that is
an exact multiple of the scale factor, and a remaining
part. Only the remaining part need be multiplied by a value
from the table before dividing by the scale factor.
|
|
|
|
|
|
| |
* mpi/make-logtab: File removed.
* mpi/make-logtab.txr: New file.
|
|
|
|
|
|
| |
* arith.c (highest_bit): On GCC, use __builtin_clz.
* mpi/mpi.c (s_highest_bit): Likewise.
|
|
|
|
|
|
|
|
|
|
|
| |
* configure: we can't assume that we can just edit "int" to
"uint" in forming the superulong_t type. Let's consolidate
the detection of the signed and unsigned superlong. Only
if both are available, then emit material into config.h,
along with a single constant: HAVE_SUPERLONG_T.
* mpi/mpi-types.h: Don't refer to removed HAVE_USUPERLONG_T.
Change superulong_t to usuperlong_t.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We support an unsigned version of the type, and add functions
for converting between Lisp values and both types.
* arith.c (bignum_dbl_uipt): New function, unsigned companion
to existing bignum_dbl_ipt.
(c_dbl_num, c_dbl_unum): New functions.
* arith.h (bignum_dbl_uipt, c_dbl_num, c_dbl_unum): Declared.
* configure (superulong_t, SIZEOF_DOUBLE_INTPTR,
DOUBLE_INTPTR_MAX, DOUBLE_INTPTR_MIN, DOUBLE_UINTPTR_MAX,
double_uintptr_t): New definitions going into config.h.
* lib.h (dbl_cnum, dbl_ucnum): New typedefs: double-sized
analogs of cnum and ucnum.
* mpi/mpi.c (mp_set_double_uintptr, mp_get_double_uintptr,
mp_get_double_intptr): New functions.
(s_mp_in_big_range): New static function.
(mp_in_double_intptr_range, mp_in_double_uintptr_range): New
functions.
* mpi/mpi.h (mp_set_double_uintptr,
mp_get_double_intptr, mp_get_double_uintptr,
mp_in_double_intptr_range, mp_in_double_uintptr_range):
Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_in_range, mp_in_intptr_range,
mp_in_uintptr_range): New functions.
* mpi/mpi.h (mp_in_range, mp_in_intptr_range,
mp_in_uintptr_range): Declared.
* arith.c (NUM_MAX_MP, INT_PTR_MAX_MP, UINT_PTR_MAX_MP,
INT_PTR_MAX_SUCC_MP): Static variables removed. Note that
INT_PTR_MAX_MP was not used at all!
(normalize): Use mp_in_range instead magnitude comparison to
NUM_MAX_MP.
(in_int_ptr_range, in_uint_ptr_range): Static functions removed.
(c_unum): Use mp_in_uintptr_range instead of
in_uint_ptr_range.
(arith_init): Remove initializations of removed variables.
(arith_free_all): Remove cleanup of removed variables, leaving
function empty.
* lib.c (c_num): Use mp_in_intptr_range instead of
in_int_ptr_range.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* mpi/mpi.h (mp_sign, mp_isneg, mp_used, mp_alloc, mp_digits,
mp_digit): New macros, based on renaming SIGN, ISNEG, USED,
ALLOC, DIGITS and DIGIT.
(mp_set_prec): Use mp_digits instead of DIGITS.
* mpi/mpi.c (SIGN, ISNEG, USED, ALLOC, DIGITS, DIGIT): Macros
defined here now, as local aliases for their namespaced
counterparts.
* arith.c (signum, floordiv): Replace ISNEG with mp_isneg.
* rand.c (random): Replace ISNEG with mp_isneg.
* sysif.c (off_t_num): Replace USED, DIGITS and ISNEG with
mp_used, mp_digits and mp_isneg.
|
|
|
|
|
|
|
|
|
| |
* mpi/mpi.c (s_mp_2expt, mp_trunc_comp, mp_trunc, mp_bit):
Arguments that give a number of bits or bit position should be
mp_size; they are not related to digit values.
* mpi/mpi.h (mp_trunc_comp, mp_trunc, mp_bit): Declaration
updated.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The flaw in the rand function caused by mp_count_ones is
serious. For instance calls to (rand 3000000000) are expected
to produce evenly distributed values in the range zero
to one less than 3 billion. Due to this flaw, only values
in the range [0, 2147483648) are produced. The function is
wrongly informed that 3000000000 is a power of two, and
so it subtracts one from the number of bits needed for the
clamping bit mask, causing raw random values to be clamped
to 31 bits instead of 32.
* arith.c (logcount): Use mp_err to capture return value from
mp_count_ones, rather than mp_size. If the result is less than
zero, throw an internal error. (The only non-internal error
indication that could come from this function is a memory
allocation, and we already use chk_malloc under MPI).
* mpi/mpi.c (mp_count_ones): Switch return type to mp_err,
because this function returns error codes, which are negative.
(mp_is_pow_two): Fix broken test that is always true.
This affects our random number module; it's used in the random
function for bignum moduli.
(mp_toradix_case): Use unsigned char temporary for exchanging
two unsigned chars, rather than a char temporary.
(s_mp_div_d): Assert that the partial quotient t and
remainder w, of mp_word_type, have values that fit into the
mp_digit variables to which they are being assigned.
(s_mp_ispow2d): The result of s_highest_bit(d) is unsigned,
so if we subtract 1 from 0, we create a large value which
likely converts to -1. Let's ensure that clearly with a cast
to (int) of the return value.
* mpi/mpi.h (mp_count_ones): Declaration updated.
* mpi/mplogic.c (mpl_rsh, mpl_lsh): Fix two places where we
shift the constant 1 (of type int) left by a number of bits
that can exceed the type int. Note, that these functions are
currently not called anywhere in TXR.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_read_radix): Take const wchar_t * string
rather than unsigned char *.
(s_mp_tovalue): Take character argument as wchar_t rather
than int.
* mpi/mpi.h (mp_read_radix): Declaration updated.
* lib.c (int_str): Avoid a malloc/free and UTF-8 conversion by
passing the original wide string to mp_read_radix.
This removes a TODO dating back to December 2011.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Sigh; this is a continuation of the same topic that was
addressed in November 14, 2016: "Fix bug in bignum addition".
Commit SHA: c30a96120f53b960db56bc05a7ce6310bb2528f5.
Though I fixed s_mp_add, s_mp_add_d has the same problem. Two
digit-sized quantities are added together in the digit-sized
type, and so the CARRYOUT(w) from the result is always zero.
This bug causes the following consequences (using behavior
under 32 bit as an example):
1. Wrong arithmetic:
(succ (pred (expt 2 32)) -> 0
2. Wrong conversion from decimal:
4294967296 -> 0
4294967297 -> 1
4294967298 -> 2
4294967299 -> 3
As well as all values that begin with the above digit
sequences.
4. Wrong conversion from floating-point.
(toint 4294967296.0) -> 0
* mpi/mpi.c (s_mp_add_d): Add missing cast to the initial
addition that adds the incoming digit d to the least
significant limb of the bignum, so that the addition is done
in the wider mp_word type, allowing CARRYOUT(w) to calculate a
nonzero k value.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This is in ANSI CL; potentially useful and hard to
implement efficiently in user code.
* arith.c (logcount): New function.
* eval.c (eval_init): Register logcount intrinsic.
* lib.h (logcount): Declared.
* mpi/mi.c (s_mp_count_ones): New static function.
(mp_count_ones): New function.
* mpi/mpi.h (mp_count_ones): Declared.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
| |
* mpi/mpi.c (s_mp_mul_d): The test used for deciding
whether or not the multiplication will carry, and possibly
needs another digit of space, is broken. There are situations
in which a carry occurs (k > 0) in spite of the test being
negative. We code this the way it should have been done in
the first place: resize the object when carry actually occurs.
This still avoids calling s_mp_pad unless absolutely
necessary, as the removed comment says. Also, in the carry
case, we need not try to clamp away leading zeros.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Using a feature of GCC, we mark some functions with the
warn_unused_result attribute. Specifically, those functions
which could return the MP_TOOBIG overflow error.
* mpi/mpi.h (mp_nign): New macro.
(mp_init_size, mp_add_d, mp_sub_d, mp_mul_d, mp_mul_2,
mp_div_d, mp_div_2, mp_expt_d, mp_add, mp_sub, mp_mul,
mp_mul_2d, mp_sqr, mp_expt, mp_2expt, mp_sqrt, mp_addmod,
mp_submod, mp_mulmod, mp_sqrmod, mp_exptmod, mp_exptmod_d,
mp_lcm, mp_xgcd, mp_invmod, mp_trunc_comp, mp_trunc, mp_shift,
mp_to_double, mp_read_signed_bin, mp_read_unsigned_bin,
mp_read_radix): Functions attributed with unused result
warning.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The main purpose of this patch is to prevent two cases of
numeric overflow.
One is when an arithmetic operation produces a result which
would have more digits than can be represented by mp_size. The
calculation for the digits in the result operand will simply
overflow, resulting in an undersized buffer that is then
overrun.
Another overflow is in calculations which work with bit
indexing. Even if the digits is in range of mp_size, the bit
number is eight times larger and can be out of range.
We can address both problems by clamping integers to have only
so many digits, that every bit has an offset that fits into
mp_size. If mp_size is 32 bits, that means we can still have
bignums that are half a gigabyte, which seems reasonable for
nearly any conceivable application of bignums.
After this patch, we must adjust the code in arith.c and
other places to detect errors, at least out of the functions
that can produce larger integers than their inputs.
* mpi/mpi-types.h (MP_MAX_BITS, MP_MAX_DIGITS): New macro.
* mpi/mpi.c (mp_err_string): New entry corresponding to the
new MP_TOOBIG error.
(mp_init_size, s_mp_grow): Reject, with the MP_TOOBIG error,
attemps to create or grow an mp_int mp_int such that it would
have more digits than MP_MAX_DIGITS.
* mpi/mpi.h (MP_TOOBIG): New macro code.
(MP_LAST_CODE): Redefined to MP_TOOBIG.
|
|
|
|
|
|
|
|
|
|
|
| |
* mpi.c (s_mp_cmp): Rewrite loop as a for with
a bottom test, and the increments in the usual place.
ap and bp aren't decremented if the index is zero.
Ironic to fix this, given that we march through the
stack in the garbage collector.
(s_mp_ispow2): Similar restructuring, with an additional
guard around ix being set up to descend from the
second-to-last digit.
|
|
|
|
| |
* mpi/mpi-config.h (MP_DEFPREC): Change from 16 to 8.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
MPI has a mp_size type for sizing of the digit arrays and some
other uses. It is not consistently used. Moreover, it is
typedef'd as a signed type. The type int is used for
iterating over digits, instead of the matching mpi_size type.
The int type is used as a size argument in some functions,
and in functions that return the number of bits.
This patch makes mp_size unsigned and replaces most uses of
int with a more appropriate type.
Because mp_size is now used for indexing, and is unsigned,
some downward loop termination tests have to be changed;
the always true condition ix >= 0 cannot be used.
* arith.c (width): Use mp_size for local variable which
iterates over digits inside mpi_int object, and for bit
count. Use unum to convert bit count to Lisp integer:
mp_size could be out of range of cnum.
* mpi/mpi-types.h (mp_size): Typedef to unsigned.
(MP_SIZE_MAX): New macro.
(MP_DIGIT_BIT, MP_WORD_BIT): Cast the value to mp_size rather
than to int.
* mpi/mpi.c (s_mp_defprec): Declare variable as mp_size.
(s_mp_setz, s_mp_copy, mp_size, s_highest_bit_mp,
s_mp_set_bit, s_mp_ispow2, s_mp_outlen, mp_set_int,
mp_set_uintptr, mp_set_double_intptr, mp_expt, mp_sqrt,
mp_exptmod, mp_hash, mp_gcd, mp_shift, mp_bit, mp_to_double,
mp_print, mp_read_signed_bin, mp_signed_bin_size,
mp_read_unsigned_bin, mp_unsigned_bin_size,
mp_to_unsigned_bin, mp_to_unsigned_buf, mp_count_bits,
mp_is_pow_two, mp_read_radix, mp_radix_size,
mp_value_radix_size, mp_toradix_case, s_mp_setz, s_mp_copy,
mp_size, s_highest_bit_mp, s_mp_set_bit, s_mp_mul_2,
s_mp_mod_2d, s_mp_div_2d, s_mp_div_d, s_mp_sqr, s_mp_sqr,
s_mp_div, s_mp_cmp, s_mp_cmp_d, s_mp_ispow2, s_mp_outlen): In
all these functions, use size_t for external size, mp_size for
number of digits and bits, in return values, arguments and
local variables. Tests in descending loops are adjusted for
unsigned logic.
* mpi/mpi.h (mp_get_prec, mp_set_prec, mp_read_signed_bin,
mp_signed_bin_size, mp_read_unsigned_bin,
mp_unsigned_bin_size, mp_to_unsigned_buf, mp_count_bits,
mp_is_pow_two, mp_radix_size, mp_value_radix_size):
Declarations updated.
* mpi/mplogic.c (mpl_not, mpl_and, mpl_or, mpl_xor, mpl_rsh,
mpl_lsh, mpl_num_set, mpl_num_clear, mpl_parity): Just like
in mpi.c
* rand.c (make_random_state): Use mp_size and ucnum for local
variables holding digit and bit counts.
* sysif.c (off_t_num): Use mp_size for digit count.
|
|
|
|
|
|
|
|
| |
* mpi/logtab.h, mpi/mpi-config.h mpi/mpi-types.h mpi/mpi.c,
mpi/mpi.h mpi/mplogic.c mpi/mplogic.h: Reformatted comments.
Removed useless comments. Removed superfluous blank lines and
whitespace. Added space between C keywords if, for, while,
sizeof and opening parens. Removed #if 0 blocks. Tabs to spaces.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This is uncovered by compiling with g++ using
-Wold-style-cast.
* mpi/mpi.c (mp_get_intptr): Use convert macro.
Also in one of the rules producing REGCHAR.
* parser.l (num_esc): Likewise.
* struct.c (static_slot_set, static_slot_ens_rec,
get_equal_method): Use coerce macro for int to pointer
conversion.
* sysif.c (setgroups_wrap): Use convert macro.
* termios.c (termios_unpack, termios_pack): Likewise.
* txr.c (sysroot_init): Likewise.
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_set_uintptr, mp_set_double_intptr): The value of z might
not require all of the digits implied by the size of its C data type.
We must clamp the result to trim trailing zero limbs from the bignum.
|
|
|
|
|
|
|
|
|
| |
* mpi/mpi-config.h: Eliminate several trailing spaces.
* mpi/mpi.c: Eliminate all trailing spaces. Removed some
commented-out code, and adjusted brace placement
and indentation in one place. Also removed some spurious
blank lines.
|
|
|
|
|
|
|
|
|
| |
* mpi/mpi.c (s_mp_add): It looks like this function had the
same kind of bug I fixed years ago in the multiplication routines.
("fix-mult-bug" patch, originally). In the main loop, two digit-sized
values are added together to produce a partial sum with carry.
Unfortunately, both operands digit-sized, so the result is truncated to
the digit type. The cast of one of the operands to mp_word is missing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* LICENSE: Reverted to Two-Clause BSD license. The
copyright of the Linenoise library are included, because
it uses exactly the same license. A note is added
about MPI being in the public domain.
* LICENSE-CYG: Revised text to clarify the situation that
Cygnal is only bundled with a particular Windows build of TXR.
* METALICENSE: Revised text. All references to modifications
to the BSD license are removed. Gives pointers to the MPI and linenoise
license files. Notes that linenoise is under the Two-Clause BSD also.
Makes a note about Cygnal and points to LICENSE-CYG.
* inst.nsi: Remove the text which tells the user that
use of the program requires agreement with the license;
refer only to redistribution. The "Agree" buttons are renamed
"Acknowledge".
* mpi/make-logtab, mpi/mpi.c, mpi/mpi.h, mpi/mplogic.c,
mpi/mplogic.h: Remove copyright notices and "all rights
reserved", since the author had placed this into the public
domain, as made explicit in the README file.
|
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_bit): If the digit index is beyond
the available digits in the number, report MP_NO rather than
accessing undefined digit material or beyond the array
entirely.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Here we ensure that the digits pointer of an uninitialized
mp_int is nulled out. The garbage collector could conceivably
encounter such an object, in which case mp_clear will then try
to free a garbage pointer. This could happen if an exception
is thrown out of numeric code due to low memory, interrupting
its execution, leaving behind an unfilled object produced
by make_ubignum.
* arith.c (make_ubignum): Perform minimal
initialization of the mp_int using new function.
* mpi/mpi.h (mp_init_minimal): New inline function.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* arith.c (logand, logior, logxor): Use make_ubignum
to create an uninitialized bignum, because mp_and, mp_or, and
mp_xor expect argument c to be uninitialized, and clobber
it by initializing.
(comp_trunc): Use make_ubignum for b argument,
because mp_trunk_comp initializes it.
(lognot, logtrunc): Use make_ubignum for b, because
mp_trunc initializes it.
* mpi/mpi.c (mp_and, mp_or, mp_xor, mp_comp, mp_trunc_comp,
mp_trunc, mp_shift, mp_bit): Do not initialize the tmp that is
passed as argument b to mp_2comp, since that function
initializes it.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This one affects all platforms. The extra sign check and
negation cancels out the one done in mp_get_uintptr, causing a
positive value for a negative input value.
* mpi/mpi.c (mp_get_intptr): Just coerce the uint_ptr_t
result to int_ptr_t. That has the right semantics under
that the bits are preserved (under two's complement, in every
compiler I've ever used). The unsigned value from
mp_get_uintptr already looks like the image of a two's
complement value.
|
|
|
|
|
|
|
|
|
| |
This applies only to some platforms, none of which are current
targets on which TXR is tested and released.
* mpi/mpi.c (mp_get_uinptr): Do not clobber output
accumulator in the loop body: the bits must be OR-ed
into it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* gc.c (gc_report_copies): C style casts found in this
function.
* linenoise.c (strip_qual, convert, coerce): Copy and paste
the macros here.
(record_undo, compare_completions, lino_add_completion,
history_search, ab_append, sync_data_to_buf,
refresh_singleline, screen_rows, refresh_multiline,
find_nearest_paren, paren_jump, yank_sel,
edit_move_matching_paren, edit, lino_make, lino_copy,
lino_hist_add, lino_hist_set_max_len): C style casts
replaced.
* mpi/mpi-types.h (MP_DIGIT_BIT, MP_DIGIT_MAX, MP_WORD_BIT,
MP_WORD_MAX, RADIX): C style casts replaced.
* mpi/mpi.c (convert, coerce): Copy and paste the macros here.
(mp_init_size, mp_init_copy, mp_copy, mp_set_int, mp_div_d,
mp_bit, mp_to_double, mp_to_signed_bin, mp_to_unsigned_bin,
mp_to_unsigned_buf, mp_toradix_case, mp_grow, s_mp_set_bit,
s_mp_mod_2d, s_mp_mul_2d, s_mp_div_2d, s_mp_mul_d, s_mp_mul,
s_mp_sqr, s_mp_div, s_mp_2expt, s_mp_todigit): C style
casts replaced.
* mpi/mplogic (convert): Macro copy and pasted here.
(mpl_num_set, mpl_num_clear): C style casts replaced.
* parser.c (provide_completions): Likewise.
* signal.c (small_sigfillset): Likewise.
* stream.c (stdio_truncate, test_set_indent_mode,
set_indent_mode): Likewise.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
These functions convert between positive integers, and
fixed-size memory buffers representing pure binary numbers in
big endian byte order.
This functionality will be used in some upcoming networking
code.
* arith.c (num_from_buffer, num_to_buffer): New functions.
* arith.h (num_from_buffer, num_to_buffer): Declared.
* mpi/mpi.c (mp_to_unsigned_buf): New function.
* mpi/mpi.h (mp_to_unsigned_buf): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* eval.c: include <assert.h> that was previously coming
via "mpi.h".
* mpi/mpi.c: Includes of <stdio.h>, <ctype.h> and <assert.h>
moved here.
* mpi/mpi.h: Remove include of <stdio.h>, <ctype.h> and
<assert.h>. Keeping <limits.h> for now; needed for CHAR_BIT.
* mpi/mplogic.c: Needs <assert.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* arith.c (UINT_PTR_MAX_MP): New static variable.
(biggnum_from_uintptr): New function.
(in_uint_ptr_range): New static function.
(c_uint_ptr_num): New function.
(arith_init): Initialize UINT_PTR_MAX_MP.
* arith.h (bignum_from_uintptr, c_uint_ptr_num): Declared.
* eval.c (eval_init): Register random-state-get-vec.
* mpi/mpi.c (mp_set_uintptr, mp_get_uintptr): New functions.
(mp_set_intptr, mp_get_intptr): Expressed in terms of
mp_set_uintptr and mp_get_uintptr.
* mpi/mpi.h (mp_set_uintptr, mp_get_uintptr): Declared.
* rand.c (make_random_state): Handle vector seed.
(random_state_get_vec): New function.
* rand.h (random_state_get_vec): Declared.
* txr.1: Documented new feature in make-random-state
and new random-state-get-vec function.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This mistake causes wasteful behavior for power-of-two
moduli in the random function, in both the bignum and
fixnum cases. For instance, the modulus 16 is taken
to be 17 bits wide. But we really want the width 16:
the number of bits needed for values in the range [0, 16).
The result isn't wrong, but the loop generates 17-bit
random numbers, and then throws away those which equal
or exceed the modulus, which is wasteful.
* mpi/mpi.c (mp_is_pow_two): New function.
* mpi/mpi.h (mp_is_pow_two): Declared.
* rand.c (random): In bignum case, after counting
bits in the modulus, subtract 1 if the modulus is a power
of two. In the fixnum case, subtract 1 from the modulus
and then count the bits in the reduced value.
* tests/013/maze.expected: regenerate due to different
prng behavior.
|
|
|
|
|
| |
* mpi/mpi-config.h, mpi/mpi.h: These headers do not
require include guards. They included only once.
|
|
|
|
|
|
|
| |
Eliminating dependencies on locale-dependent C functions.
* mpi/mpi.c (s_mp_tovalue, s_mp_todigit): Avoid tolower, toupper,
islower and isupper.
|
|
|
|
|
|
|
|
|
|
|
| |
Adding bit operations to MPI.
* mpi/mpi.c (MAX, MIN): New macros.
(mp_2comp, mp_and, mp_or, mp_xor, mp_comp, mp_trunc, mp_shift,
mp_bit): New functions.
* mpi/mpi.h (mp_2comp, mp_and, mp_or, mp_xor, mp_comp, mp_trunc,
mp_shift, mp_bit): Declared.
|
|
|
|
|
| |
* mpi/mpi.c (s_mp_tovalue): Argument changes from char to int,
fixing some compiler warnings.
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_to_double): New function.
* mpi/mpi.h (mp_to_double): Declared.
|
|
|
|
|
| |
* mpi/mpi.c (s_highest_bit_mp, s_mp_set_bit): New functions.
(mp_sqrt): Rewrite with more efficient algorithm.
|
|
|
|
|
|
| |
* mpi/mpi.h (mp_int): Depending on the relative size of int and pointers,
turn the sign and alloc fields into bitfields, so that the structure
is three words wide and therefore fits into a TXR obj_t heap object.
|
|
|
|
|
| |
* mpi/mpi.c (s_highest_bit): New static function.
(s_mp_norm, s_mp_ispow2): Use s_highest_bit instead of looping over bits.
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_div_d, s_mp_mod_2d, s_mp_mul_2d, s_mp_div_2d,
s_mp_2expt): Fixing incorrect digit-wide left shifts whre the operand
is not widened to the mp_digit type.
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_set_double_intptr): New function.
* mpi/mpi.h (mp_set_double_intptr): Declared.
|