@@ -492,10 +492,11 @@ for (T, U) in [(UInt8, UInt32), (UInt16, UInt32),
492
492
end
493
493
494
494
immutable RangeGeneratorBigInt <: RangeGenerator
495
- a:: BigInt # first
496
- m:: BigInt # range length - 1
497
- nlimbs:: Int # number of limbs in generated BigInt's
498
- mask:: Limb # applied to the highest limb
495
+ a:: BigInt # first
496
+ m:: BigInt # range length - 1
497
+ nlimbs:: Int # number of limbs in generated BigInt's (z ∈ [0, m])
498
+ nlimbsmax:: Int # max number of limbs for z+a
499
+ mask:: Limb # applied to the highest limb
499
500
end
500
501
501
502
@@ -506,7 +507,8 @@ function RangeGenerator(r::UnitRange{BigInt})
506
507
nlimbs, highbits = divrem (nd, 8 * sizeof (Limb))
507
508
highbits > 0 && (nlimbs += 1 )
508
509
mask = highbits == 0 ? ~ zero (Limb) : one (Limb)<< highbits - one (Limb)
509
- return RangeGeneratorBigInt (first (r), m, nlimbs, mask)
510
+ nlimbsmax = max (nlimbs, abs (last (r). size), abs (first (r). size))
511
+ return RangeGeneratorBigInt (first (r), m, nlimbs, nlimbsmax, mask)
510
512
end
511
513
512
514
539
541
function rand (rng:: AbstractRNG , g:: RangeGeneratorBigInt )
540
542
x = BigInt ()
541
543
ccall ((:__gmpz_realloc2 , :libgmp ), Void, (Ptr{BigInt}, Culong), & x,
542
- g. nlimbs * 8 * sizeof (Limb))
544
+ g. nlimbsmax * 8 * sizeof (Limb))
543
545
limbs = unsafe_wrap (Array, x. d, g. nlimbs)
544
546
while true
545
547
rand! (rng, limbs)
0 commit comments