aboutsummaryrefslogtreecommitdiff
path: root/core/math/big/internal.odin
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2021-09-03 01:25:18 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2021-09-03 01:25:18 +0200
commiteecc786bd2d7d3717b84d2828f535e19c92fc66b (patch)
treea5e53e5d3af279511d7d9886ef246d8f740e9dfe /core/math/big/internal.odin
parent7fa04fa018297bafb148533581bf9756b560c256 (diff)
big: Add Frobenius-Underwood.
Diffstat (limited to 'core/math/big/internal.odin')
-rw-r--r--core/math/big/internal.odin12
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 {