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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(in) | :: | span_minus_1 |
One less than the number of distinct values wanted, unsigned. |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | shift |
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