aboutsummaryrefslogtreecommitdiff
path: root/core/math/big/private.odin
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2025-11-18 15:37:57 +0100
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2025-11-18 15:37:57 +0100
commit56aab55d8250ee8191583d6b5e97eace89cfbef7 (patch)
treef002236da77d904520112e2236d658cebd7149e1 /core/math/big/private.odin
parent784f320e12721761af494816cf07ed08d00deced (diff)
Fix #5931
Fix #5931 and add test case for it.
Diffstat (limited to 'core/math/big/private.odin')
-rw-r--r--core/math/big/private.odin11
1 files changed, 3 insertions, 8 deletions
diff --git a/core/math/big/private.odin b/core/math/big/private.odin
index fb517f0b7..4847b0074 100644
--- a/core/math/big/private.odin
+++ b/core/math/big/private.odin
@@ -1050,7 +1050,6 @@ _private_int_div_school :: proc(quotient, remainder, numerator, denominator: ^In
Normalize both x and y, ensure that y >= b/2, [b == 2**MP_DIGIT_BIT]
*/
norm := internal_count_bits(y) % _DIGIT_BITS
-
if norm < _DIGIT_BITS - 1 {
norm = (_DIGIT_BITS - 1) - norm
internal_shl(x, x, norm) or_return
@@ -1070,33 +1069,29 @@ _private_int_div_school :: proc(quotient, remainder, numerator, denominator: ^In
y = y*b**{n-t}
*/
+
_private_int_shl_leg(y, n - t) or_return
- gte := internal_gte(x, y)
- for gte {
+ for internal_gte(x, y) {
q.digit[n - t] += 1
internal_sub(x, x, y) or_return
- gte = internal_gte(x, y)
}
/*
Reset y by shifting it back down.
*/
_private_int_shr_leg(y, n - t)
-
/*
Step 3. for i from n down to (t + 1).
*/
#no_bounds_check for i := n; i >= (t + 1); i -= 1 {
if i > x.used { continue }
-
/*
step 3.1 if xi == yt then set q{i-t-1} to b-1, otherwise set q{i-t-1} to (xi*b + x{i-1})/yt
*/
if x.digit[i] == y.digit[t] {
- q.digit[(i - t) - 1] = 1 << (_DIGIT_BITS - 1)
+ q.digit[(i - t) - 1] = 1 << _DIGIT_BITS - 1
} else {
-
tmp := _WORD(x.digit[i]) << _DIGIT_BITS
tmp |= _WORD(x.digit[i - 1])
tmp /= _WORD(y.digit[t])