rejection_mask Function

private pure function rejection_mask(span_minus_1) result(mask)

Smallest 2**k - 1 that covers span_minus_1 read as unsigned.

Smears the highest set bit down over every bit below it. A span_minus_1 of -1, which as unsigned is 2**64 - 1, gives a mask of -1, under which every draw is accepted – which is right, because that span is the whole word.

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(in) :: span_minus_1

One less than the number of distinct values wanted, unsigned.

Return Value integer(kind=int64)


Calls

proc~~rejection_mask~2~~CallsGraph proc~rejection_mask~2 rejection_mask proc~u64_shr u64_shr proc~rejection_mask~2->proc~u64_shr

Called by

proc~~rejection_mask~2~~CalledByGraph proc~rejection_mask~2 rejection_mask proc~pcg32_uniform_below pcg32_uniform_below proc~pcg32_uniform_below->proc~rejection_mask~2 proc~splitmix64_uniform_below splitmix64_uniform_below proc~splitmix64_uniform_below->proc~rejection_mask~2 proc~pcg32_next_bernoulli_ppm pcg32_next_bernoulli_ppm proc~pcg32_next_bernoulli_ppm->proc~pcg32_uniform_below proc~pcg32_next_range pcg32_next_range proc~pcg32_next_range->proc~pcg32_uniform_below proc~splitmix64_next_bernoulli_ppm splitmix64_next_bernoulli_ppm proc~splitmix64_next_bernoulli_ppm->proc~splitmix64_uniform_below proc~splitmix64_next_range splitmix64_next_range proc~splitmix64_next_range->proc~splitmix64_uniform_below interface~next_bernoulli_ppm next_bernoulli_ppm interface~next_bernoulli_ppm->proc~pcg32_next_bernoulli_ppm interface~next_bernoulli_ppm->proc~splitmix64_next_bernoulli_ppm interface~next_range next_range interface~next_range->proc~pcg32_next_range interface~next_range->proc~splitmix64_next_range

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: shift

Source Code

   pure function rejection_mask(span_minus_1) result(mask)
      !! Smallest `2**k - 1` that covers `span_minus_1` read as unsigned.
      !!
      !! Smears the highest set bit down over every bit below it. A
      !! `span_minus_1` of -1, which as unsigned is 2**64 - 1, gives a mask of
      !! -1, under which every draw is accepted -- which is right, because
      !! that span is the whole word.
      integer(int64), intent(in) :: span_minus_1
         !! One less than the number of distinct values wanted, unsigned.
      integer(int64) :: mask

      integer(default_int) :: shift

      mask = span_minus_1
      shift = 1_default_int
      do while (shift < 64_default_int)
         mask = ior(mask, u64_shr(mask, shift))
         shift = shift*2_default_int
      end do
   end function rejection_mask