| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
| |
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 (mp_to_double): New function.
* mpi/mpi.h (mp_to_double): Declared.
|
|
|
|
|
|
| |
* 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 (mp_set_double_intptr): New function.
* mpi/mpi.h (mp_set_double_intptr): Declared.
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_set_word): New function.
* mpi/mpi.h (mp_set_word): Declared.
|
|
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_toradix_case): New function based on mp_toradix. Takes
an argument whether to use lower case digits.
(mp_toradix): Reduced to wrapper for mp_toradix_case.
* mpi/mpi.h (mp_toradix_case): Declared.
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_hash): New function.
* mpi/mpi.c (mp_hash): Declared.
|
|
|
|
|
|
| |
* mpi/mpi.c (MP_LT, MP_EQ, MP_GT): Preprocessor symbols removed.
* mpi/mpi.h (MP_LT, MP_EQ, MP_GT): Preprocessor symbols added.
|
|
|
|
|
|
| |
* mpi/mpi.c (mp_set_intptr, mp_get_intptr): New functions.
* mpi/mpi.h (mp_set_intptr, mp_get_intptr): Declared.
|
|
Importing 1.8.6 upstream baseline, minus unwanted stuff.
|