mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-02 21:10:27 +02:00
* random.c (scm_i_random_bignum): Made independent of endianness.
This commit is contained in:
parent
b7965ba977
commit
96e263d633
1 changed files with 7 additions and 5 deletions
|
@ -261,10 +261,10 @@ scm_i_random_bignum (SCM m, scm_rstate *state)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* fix most significant 32 bits */
|
/* fix most significant 32 bits */
|
||||||
#if SIZEOF_INT == 4 && defined (WORDS_BIGENDIAN)
|
#if SIZEOF_INT == 4
|
||||||
w = SCM_BDIGITS (m)[nd - 1] << 16 | SCM_BDIGITS (m)[nd - 2];
|
w = SCM_BDIGITS (m)[nd - 1] << 16 | SCM_BDIGITS (m)[nd - 2];
|
||||||
#else
|
#else
|
||||||
w = ((LONG32 *) SCM_BDIGITS (m))[nd / 2 - 1];
|
w = SCM_BDIGITS (m)[nd - 1];
|
||||||
#endif
|
#endif
|
||||||
mask = (w < 0x10000
|
mask = (w < 0x10000
|
||||||
? (w < 0x100
|
? (w < 0x100
|
||||||
|
@ -291,11 +291,13 @@ scm_i_random_bignum (SCM m, scm_rstate *state)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* fix most significant 32 bits */
|
/* fix most significant 32 bits */
|
||||||
i /= 2;
|
#if SIZEOF_INT == 4
|
||||||
#if SIZEOF_INT == 4 && defined (WORDS_BIGENDIAN)
|
|
||||||
w = scm_the_rng.random_bits (state) & mask;
|
w = scm_the_rng.random_bits (state) & mask;
|
||||||
bits[--i] = (w & 0xffff) << 16 | w >> 16;
|
((SCM_BIGDIG*) bits)[i - 2] = w & 0xffff;
|
||||||
|
((SCM_BIGDIG*) bits)[i - 1] = w >> 16;
|
||||||
|
i = i / 2 - 1;
|
||||||
#else
|
#else
|
||||||
|
i /= 2;
|
||||||
bits[--i] = scm_the_rng.random_bits (state) & mask;
|
bits[--i] = scm_the_rng.random_bits (state) & mask;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue