diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-09-03 01:25:18 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-09-03 01:25:18 +0200 |
| commit | eecc786bd2d7d3717b84d2828f535e19c92fc66b (patch) | |
| tree | a5e53e5d3af279511d7d9886ef246d8f740e9dfe /core/math/big/internal.odin | |
| parent | 7fa04fa018297bafb148533581bf9756b560c256 (diff) | |
big: Add Frobenius-Underwood.
Diffstat (limited to 'core/math/big/internal.odin')
| -rw-r--r-- | core/math/big/internal.odin | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/core/math/big/internal.odin b/core/math/big/internal.odin index c603dcdd8..6ae2f4284 100644 --- a/core/math/big/internal.odin +++ b/core/math/big/internal.odin @@ -2019,8 +2019,18 @@ internal_invmod :: proc{ internal_int_inverse_modulo, }; /* Helpers to extract values from the `Int`. */ +internal_int_bitfield_extract_bool :: proc(a: ^Int, offset: int) -> (val: bool, err: Error) { + limb := offset / _DIGIT_BITS; + if limb < 0 || limb >= a.used { return false, .Invalid_Argument; } + i := _WORD(1 << _WORD((offset % _DIGIT_BITS))); + return bool(_WORD(a.digit[limb]) & i), nil; +} + internal_int_bitfield_extract_single :: proc(a: ^Int, offset: int) -> (bit: _WORD, err: Error) { - return #force_inline int_bitfield_extract(a, offset, 1); + limb := offset / _DIGIT_BITS; + if limb < 0 || limb >= a.used { return 0, .Invalid_Argument; } + i := _WORD(1 << _WORD((offset % _DIGIT_BITS))); + return 1 if ((_WORD(a.digit[limb]) & i) != 0) else 0, nil; } internal_int_bitfield_extract :: proc(a: ^Int, offset, count: int) -> (res: _WORD, err: Error) #no_bounds_check { |