mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-05 20:48:04 +00:00
Merge pull request #3431 from Feoramund/fix-randprime-2ndmsb
Fix `big.internal_random_prime` with `Second_MSB_On`
This commit is contained in:
@@ -1247,6 +1247,20 @@ internal_random_prime :: proc(a: ^Int, size_in_bits: int, trials: int, flags :=
|
||||
a.digit[0] |= 3
|
||||
}
|
||||
if .Second_MSB_On in flags {
|
||||
/*
|
||||
Ensure there's enough space for the bit to be set.
|
||||
*/
|
||||
if a.used * _DIGIT_BITS < size_in_bits - 1 {
|
||||
new_size := (size_in_bits - 1) / _DIGIT_BITS
|
||||
|
||||
if new_size % _DIGIT_BITS > 0 {
|
||||
new_size += 1
|
||||
}
|
||||
|
||||
internal_grow(a, new_size) or_return
|
||||
a.used = new_size
|
||||
}
|
||||
|
||||
internal_int_bitfield_set_single(a, size_in_bits - 2) or_return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user